Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: count decimals 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: count decimals
    Posted: 19 Jun 2012 at 7:45am

Hello

 

I'm trying to count the portion of a number after the dot but so far no luck.

For example the field is number with value 10.7523, just like to return 2 since there are 2 digits after the dot

 

 

Formula1: instr(totext({table1.price}),”.”)   ---à>> it will return 3 which is good

Formula2: mid(totext({table1.price}),{@Formula1}+1)  --
à>> it returns only 75 and not 7523, not sure why

Formula3: len({@Formula2}) --à>>> it will return 2 since only 2 digits count in formula2, but in itself, this one is not a problem

Thanks
TT


Edited by Athlon - 20 Jun 2012 at 2:20am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 19 Jun 2012 at 11:35am

You're only getting two digits in Formula 2 because the default number format when using ToText is two digits after the decimal.

 
-Dell
IP IP Logged
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Posted: 20 Jun 2012 at 2:20am
thanks
I have no choice but using totext, since instr can only work with string.
Would you know of different way of counting the decimal?
 
thanks
TT
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 20 Jun 2012 at 3:01am

totext({field} ,3)  will give you 3 decimal places.

if you have Crystal Help installed, search on ToText and it will tell you all the possible parameters

 

IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 20 Jun 2012 at 3:50am
As you don't know how many decimals you need to specify for the totext function this is how I'd do it.
 
numbervar x:= abs({table.field});
stringvar y:= strreverse(totext(x,10,""));
numbervar z:= tonumber(y);
numbervar c:= len(totext(z,0,""));
c
 
Maximum of 10 decimal places allowed by the totext function I'm afraid.
 
Regards,
Ryan.


Edited by rkrowland - 20 Jun 2012 at 4:00am
IP IP Logged
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Posted: 20 Jun 2012 at 9:03am
Hello there
 
How I could ever thank you for this? but thank you thousand times!
 
It works....I would never have have thought of the abs + strreverse
 
thanks Clap
 
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: 20 Jun 2012 at 9:56pm
No problem, looking at it again I've seen a possibility of it being incorrect, the below will fix it;
 
numbervar x:= abs({table.field});

stringvar y:= strreverse(totext(x,10,""));
numbervar z:= truncate(tonumber(y));
numbervar c:= len(totext(z,0,""));

c
 
An example that could go wrong would be a starting value of 8.999, the entire process would go as follows;
 
x = 8.999
y = 0000000999.8
z = 999.8
 
now here's where the error would be, the totext(z,0,"") part of c would return 1000, giving a count of 4, adding the truncate to the formula give a return of 999 which gives us the correct count of 3.
 
Regards,
Ryan.


Edited by rkrowland - 20 Jun 2012 at 10:03pm
IP IP Logged
Athlon
Newbie
Newbie


Joined: 19 Jun 2012
Location: United States
Online Status: Offline
Posts: 7
Quote Athlon Replybullet Posted: 21 Jun 2012 at 9:32am
Thanks again
 
TT
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.016 seconds.