Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: display decimal Post Reply Post New Topic
Author Message
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Topic: display decimal
     Posted: 02 Jul 2012 at 2:56am
Hello everyone
 
I have this float column with following values
 
Data in db          Like to display 
                          using my formula      but Crystal will display
=======          ===========        ============
 
14                      14                            14.0000     
14.1                   14.10                       14.1000
14.12                 14.12                       14.1200
14.123               14.1230                   14.1230
14.1234             14.1234                   14.1234
14.12345           14.1234                   14.1235
 
and I have tried this formula using the decimals field from number tab
but it doesn't seem to work, the only thing seems to work is the 'else 4'
 
I'm not sure what's missing, thanks in advance for the help
 
if {table1.column1} = 0
   then 0
else if {table1.column1} = 1
   then 2
else if {table1.column1} = 2
   then 2
else
   4
                   
TT
 
 
 
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 02 Jul 2012 at 3:29am
Try this;
 
numbervar x:= abs({table.field});
stringvar y:= strreverse(totext(x,10,""));
numbervar z:= truncate(tonumber(y));
numbervar c:= len(totext(z,0,""));
if z = 0 then 0
else
if c <= 2 then 2
else
4
 
Regards,
Ryan.


Edited by rkrowland - 02 Jul 2012 at 3:29am
IP IP Logged
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Posted: 02 Jul 2012 at 3:45am
Ryan
 
You helped me last time with that formula, from the result of the len, you can then use that number for the decimal, it worked perfectly.
 
I was just wondering, why when using the formula directly against the column it didn't work, or only worked with the portion 'else' at the end and nothing else above that
 
anyway, thanks again
 
TT
 
 
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 02 Jul 2012 at 5:17am
Well it didn't work when using the formula directly against the column as your original formula was working with the value of the field, not the number of decimal places in the field, for example -
 
We'll assume in this instance the db value of {table1.column1} = 14.12, this is what your formula is asking;
 
if 14.12 = 0
   then 0
else if 14.12 = 1
   then 2
else if 14.12 = 2
   then 2
else
   4
 
As you can see, the result is almost always going to be 4.
 
Where as my formula will be asking the following with the same db value (14.12)
 
if 21 = 0 then 0
else
if 2 <= 2 then 2
else
4
 
Here you see the 2 decimal places is less than or equal to 2 so the formula will return 2 decimal places.
 
Hope that helps.
 
Regards,
Ryan.


Edited by rkrowland - 02 Jul 2012 at 5:25am
IP IP Logged
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Posted: 03 Jul 2012 at 7:06am
Ryan
 
Yes it helps
 
I see what you mean now, for some reason I though the 'if {table1.column1} for that particular instance was referring to the number of digist after the dot, it wasn't, it referred to real value of that column then for sure, it's almost alway 4
 
Thanks very much for your time Ryan
 
TT
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