How to remove unwanted zeros from decimal numbers in Crystal Reports

advertisements

In My Crystal Report, I have three type of decimal numbers.

 1) 11.00 , 2.00

 2) 2.50, 1.30

 3) 11.75, 2.25

I need to format those 3 types as following

 1) 11, 2

 2) 2.5, 1.3

 3) 11.75, 2.25

That means I want to remove unwanted zeros from my decimal numbers. How can do it?


  • right click the field on the report canvas
  • select format field
  • select number tab
  • select custom style
  • select customize
  • Next to decimal select the X-2 box and enter the following formula

    numbervar dec := 9;
    numbervar i;
    numbervar j := dec + 1;
    numbervar x;
    
    for i := 1 to j do (
    if val(right(totext(currentfieldvalue,j,""),i)) = 0 then
    x := j  - i);
    x
    
    

below that select the X-2 button next to rounding and enter this formula

numbervar dec;