Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Display of decimal places in a calculated formula Post Reply Post New Topic
Author Message
bernieL
Newbie
Newbie


Joined: 24 Sep 2010
Location: Canada
Online Status: Offline
Posts: 3
Quote bernieL Replybullet Topic: Display of decimal places in a calculated formula
     Posted: 24 Sep 2010 at 4:02am
I have a formula that I have created that works but does not display the end result as expected.  The code looks like this
 
if (isnull({agt_rx.rx_dose_range}) or {agt_rx.rx_dose_range} <= 0)  then totext({agt_rx.rx_dose} / tonumber({agt_rx.dose_strength}),0) else
totext({agt_rx.rx_dose}/tonumber({agt_rx.dose_strength}),0)&" to "& totext(({agt_rx.rx_dose_range}/tonumber({agt_rx.dose_strength})),0)
 
Doing it this way, the numbers display as whole numbers only so if it sees a 0.5 it displays it as 1.  What I would like to have the number display as is as follows.
 
I can get the number to display like this without a problem
 
1.0500
1.4050
1.2345
 
But what I need is for the numbers to display like this
 
1.05
1.405
1.2345
 
The formula above is used in calculating medications so it's one of 6 formulas added to a text box on the report so I can not conditional  format the "number display". is there a way to tweak this code to make it display correctly?


Edited by bernieL - 25 Sep 2010 at 8:42am
IP IP Logged
bernieL
Newbie
Newbie


Joined: 24 Sep 2010
Location: Canada
Online Status: Offline
Posts: 3
Quote bernieL Replybullet Posted: 25 Sep 2010 at 3:19am
With many views so far a not a single suggestion I think I need to ask the question;  Does anyone think this is possible?


Edited by bernieL - 25 Sep 2010 at 3:21am
IP IP Logged
bernieL
Newbie
Newbie


Joined: 24 Sep 2010
Location: Canada
Online Status: Offline
Posts: 3
Quote bernieL Replybullet Posted: 28 Sep 2010 at 5:50pm

I found this on another forum and it worked except it still displays a zero where the field = zero.  Can someone assist me in tweaking the code so it will not display zero.


WhilePrintingRecords; NumberVar p1; NumberVar p2;
StringVar s1;
s1 := ToText({agt_rx.rx_dose_range} / tonumber({agt_rx.dose_strength}),"0.000000000000000");
p1 := instr(s1,".");
p2 := instr(s1+"000000000000000","000000000000000");
if (p2 = p1+1) then s1 := left(s1,p1-1)
               else s1 := left(s1,p2-1);
     s1;

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