Reputation: 580
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?
Upvotes: 2
Views: 2734
Reputation: 926
Create Custom Function with this code:
Function (NumberVar nNumber)
Local StringVar sNumber := ToText(nNumber, 5); // 5 digits after floating point
sNumber := Replace(sNumber, "0", " "); // replacing 0 to whitespaces so that TrimRight will work
sNumber := TrimRight(sNumber);
sNumber := Replace(sNumber, " ", "0"); // replacing whitespaces back to 0
// Remove . at the end if the number was an integer
If Right(sNumber, 1) = "." Then
sNumber := Left(sNumber, Length(sNumber)-1);
sNumber;
Upvotes: 0
Reputation: 9091
Try This:
if ".0" IN ToText({ABC.ABC})
then
Replace(Replace (ToText({ABC.ABC}), ".0","" ),"0","")
else
Replace (ToText({ABC.ABC}), "0","" )
Upvotes: 1
Reputation: 1645
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;
Upvotes: 2