Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional formatring of decimal point 4

Status
Not open for further replies.

melburstein

Technical User
Aug 29, 2000
246
US
I am a relatively new user of Crystal Reports 9, so I need some step-by-step guidance. Command is the name of the table I am using. Each detail line of my report prints a GL account number (Command.ACCOUNT(Number) and several numbers (Command.CPUNT1, Command.CPUNT2, etc.). The numbers are statistics, some of which need to appear as intigers and some with two positions to the right of the decimal. For example: if ACCOUNT is equal to 990061 or 990067, I want CPUNT1, CPUNT2, etc. to print with a decimal and two positions to the right; otherwise I want to see an integer without any decimal.

Your help is appreciated.

Mel
 
There might be a simpler way to do this...

However, what I've done in the past is to use two copies of the field placed on top of each other. Use the conditional Suppress formula for the field to determine which of the two actually appears on the report. For example, put the following in the suppress formula for the field with the decimal point:

({Command.ACCOUNT} <> 990061) and ({Command.ACCOUNT} <> 990067)

For the one without the decimal point, you would put the follwing in the suppress formula:

({Command.ACCOUNT} = 990061) or ({Command.ACCOUNT} = 990067)

-D
 
In the custom formatting of the field, setup a formula on its decimal places formula like

if (CurrentFieldValue = 990061)
or (CurrentFieldValue = 990067) then
0 //number of decimal places
else 2

This doesn't require 2 separate fields to lose in the jumble and would make it easier to handle additional special cases.

if CurrentFieldValue =
ToNumber(ToText(CurrentFieldValue,0)) then
0
else 2

is the one I use occasionally to display whole numbers without trailing zeros.

Scotto the Unwise
 
you are not 100% clear on this

*************
.). The numbers are statistics, some of which need to appear as intigers and some with two positions to the right of the decimal. For example: if ACCOUNT is equal to 990061 or 990067, I want CPUNT1, CPUNT2, etc. to print with a decimal and two positions to the right; otherwise I want to see an integer without any decimal.

*************

Does this mean that if Account is 990061 or 990067 then your numbers which are originally say 123 in the database atre to be displayed 1.23???

Another question that needs to be asked...are you just dispalying these number or are you using them for calculations as well?

For display you could do this...I am assuming {Table.Account} is a string...if not remove the quotes

//@DisplayCPUNT1 (suppressed in details section)
WhilePrintingRecords;

if {Table.Account} in [&quot;990061&quot;,&quot;990067&quot;] then
totext({Table.CPUNT1},2)
else
totext({Table.CPUNT1},0);

Do the same for all the other CPUNT's

If the numbers are to be used in calculations later then


//@DisplayCPUNT1 (suppressed in details section)
WhilePrintingRecords;
NumberVar CPUNT_1;
StringVar temp;

if {Table.Account} in [&quot;990061&quot;,&quot;990067&quot;] then
(
CPUNT_1 := {Table.CPUNT1}/100;
Temp := totext({Table.CPUNT1},2);
)
else
(
CPUNT_1 := {Table.CPUNT1};
Temp := totext({Table.CPUNT1},0);
);

Temp;

now the number is stored for future use


Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
All 3 posts were helpful. To answer Jim's question, the statistics are stored in the database with two decimals. It is only for presentation purposes that we want some to print without decimals. And none of those values will be used for calculations.

Taking the advice you all gave me, I attached the following formula (a composite of your various suggestions) to CPUNT1, CPUNT2, CPUNT3, etc.

if ({Command.ACCOUNT} = 990061) or ({Command.ACCOUNT} = 990062) or ({Command.ACCOUNT} = 990065)
or ({Command.ACCOUNT} = 990066) or ({Command.ACCOUNT} = 990067) then
2//number of decimal places
else 0

I do not fully understand formulas, so there may have been a cleaner way to write this one, but it works. It works great! And I was able to use the same formula for all the fields.

Thanks again, everyone.
 
This would be a cleaner way.

if {Command.ACCOUNT} in [990061,990062,990065,990066,990067] then 2 else 0

If you're just starting out with formulas, then I would recommend spending 30 to 60 minutes putting in different selection formulas through the Select expert, then going into Show Formula, Formula Editor to see the syntax used.

The above formula would have been displayed had you used the 'is one of' selection.


Reebo
UK
 
Thank you Reebo. I have replaced the formula that I created with your shorter version. And thanks for the advice.
 
Thank you Reebo for offering a simplified formula. I am using it and, of course, it works fine.
 
Looks like I forgot the brackets in my formula

if {Table.Account} in [&quot;990061&quot;,&quot;990067&quot;] then

Oh well seems you have it sorted out now

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top