Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding Percentages

Status
Not open for further replies.

dbaJSmith

Programmer
Sep 17, 2008
42
US
Hello all:
Using CR XI, trying to create a combined summary in one field. Example of result:

Individuals Tested: 450
Yes Cases: 400 / 88.89%
No Cases: 50 / 11.11%

I can't seem to get the percentages to round to two significant digits:

***************
whileprintingrecords;

numbervar CountYes;
numbervar CountTotal;

if CountTotal <> 0 then
CountYes & " / " & round(CountYes%CountTotal,2) & "%"
else
"0 / 0%"
***************
Result:
Yes Cases: 400 / 88%

The "No Cases" formula is the same other than CountNo. At first, I thought this might be a limitation of the % function, so I tried a longer version:

************
whileprintingrecords;

numbervar CountYes;
numbervar CountTotal;

if CountTotal <> 0 then
CountYes & " / " & round(CountYes / CountTotal * 100, 2) & "%"
else
"0 / 0%"
***********
Result:
Yes Cases: 400 / 88%

Any ideas? Thanks!
 
Just wrap this segment in totext as follows:

totext(round(CountYes%CountTotal,2),2)

-LB
 
Ahhh - I fiddled with totext before, but I didn't know that it had conditional modifiers for this situation. thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top