Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Remove trailing 0s Post Reply Post New Topic
Author Message
mabrown
Newbie
Newbie


Joined: 08 Jun 2007
Online Status: Offline
Posts: 27
Quote mabrown Replybullet Topic: Remove trailing 0s
     Posted: 12 Aug 2013 at 3:55am
We want to remove the trailing 0s from the results of the following formula.

if {invoice.status} = "S" then
     (ToText({invoice.quantity},3,''))
else
    "0"

Right now it can returns
1.000
1.500
0.500
6.125

We want it to return
1
1.5
0.5
6.125

Thank you
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 12 Aug 2013 at 4:44am
I think that the only way that you can do that is to make it a string and manipulate the string. Something like:

local numbervar i;
local stringvar x:=totext({table.field}); //or from a formula, or inside of the formula

for i:=len(x) to 1 step -1(
if mid(x,i,1)=0 then
   x:= left(x,i-1);
else
   break;//I think it is break, but it might be exit or exit for
);
x

At least it is a pointer in the right direction. Aligning the number will be problem. You could try replacing the 0 with a space, but with true type fonts the decimal place won't align...

just things to consider.

IP IP Logged
praveeng
Senior Member
Senior Member
Avatar

Joined: 11 Jul 2011
Online Status: Offline
Posts: 165
Quote praveeng Replybullet Posted: 12 Aug 2013 at 4:46am
Hi
 
Change the formula as below
 
stringvar Decimal:=split(Database field,".")[2];
if Decimal[3] <> "0" then
  ToText(Val(Database field), 3, "")
else if Decimal[2] <> "0" then
  ToText(Val(Database field), 2, "")
else if Decimal[1] <> "0" then
  ToText(Val(Database field), 1, "")
else
  ToText(Val(Database field), 0, "")
 
Praveen Guntuka,
praveen_guntuka@yahoo.com
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum