Michael Katz
asked on
Only show decimals when there are non zero decimals in Crystal Reports
I have a number field that may be 1.00 which I only want to show 1..
but if its 1.05 I want it to show 1.05
Any ideas??
but if its 1.05 I want it to show 1.05
Any ideas??
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this one
Right click the field
Click FORMAT FIELD
Click the NUMBER TAB
CLick the formula button to the right of Decimals
Enter this formula
If {YourFIeld} = Round ({YourFIeld}) then
0
Else If {YourFIeld} = Round ({YourFIeld},1) then
1
Else If {YourFIeld} = Round ({YourFIeld},2) then
2
Else
3
Click OK
Set Rounding to 0.001
mlmcc
Right click the field
Click FORMAT FIELD
Click the NUMBER TAB
CLick the formula button to the right of Decimals
Enter this formula
If {YourFIeld} = Round ({YourFIeld}) then
0
Else If {YourFIeld} = Round ({YourFIeld},1) then
1
Else If {YourFIeld} = Round ({YourFIeld},2) then
2
Else
3
Click OK
Set Rounding to 0.001
mlmcc
ASKER
Which formula button to the right of the decimals??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Concise and well done... Pretty straightforward from both of these guys...Par for the course with James and mlmcc
If you use the usual right alignment and simply remove the decimals, you end up with values like this:
Open in new window
Also, do you want to always display 2 decimal places on non-integers, or only display the required number of places? For example, should 3.5 be shown as 3.50, or just 3.5 ?
If you want to always display 2 decimal places on non-integers, you can go to the field format, click Customize on the Number tab, click the formula (X+2) button beside Decimals and enter this formula:
if CurrentFieldValue = Truncate (CurrentFieldValue) then
0
else
2
Rounding would presumably be set to 2 places. You could use the same formula for Rounding, but it doesn't seem necessary, since you're only hiding the decimals when they're 0.
James