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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Display or Suppress Trailing Decimals for Numeric Field

Status
Not open for further replies.

rose4567

Programmer
Mar 12, 2007
70
US
Hi there,

I have a field I am trying to format in Crystal Reports 10. This seems like it should be simple, but I can't figure it out.

The field is numeric and is stored in the database like: 1.00, 1.25, 1.50, etc.

If the value is like 1.00 I want output to look like: 1.

If the value is 1.25 I want output to look like: 1.25.

If the value is 1.50 I want output to look like: 1.5.

Do I create a formula field to drive output? Or should I be formatting the field itself? I am not sure how to write the formula to product the output I'm looking for. Any help would be greatly appreciated.

Thank you!!

 
In format number go to customise, in the formula box x2 opposite decimals do something like

if Remainder({numberfield}*100, 100) = 0 then 0
if Remainder({numberfield}*100, 10) = 0 then 1
else 2

Ian
 
You can use a formula like this in the format number->customize style->decimals->x+2 area:

numbervar dec := 9;
numbervar i;
numbervar j := dec + 1;
numbervar x;

for i := 1 to j do (
if val(right(totext({table.amt},j,""),i)) = 0 then
x := j - i);
x

You must also change the rounding just below it to the maximum number of decimals.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top