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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate a Percent but Display Text 1

Status
Not open for further replies.

baycolor

MIS
Mar 23, 2005
148
US
Hi,

I'm using CRV11.

I have a numerator and a denominator which I'm using to calculate a percent from.

numerator / denominator * 100

If the answer is 55.23% I want to output via my formula result column 55.2% I can do this easily by using the formattting field options and select the number of decimal places to display and via the "%" toolbar button I can add a percent sign.

I'm checking to make sure that my formula doesn't divide by zero. In that case though I want to display the output string "n/a". This is where I'm having trouble. CR doens't like the formula like

If denominator <> 0 then
numerator / denominator * 100
else "n/a"

as it expects a number in the else portion.

I did attempt to skip the field formatting and convert my output to text and deal with it that way but I'm having a problem with that.
If I round my output then truncate it then truncate it and then concatenate a "%" sign I thought I could get what I wanted but that doesn't work either. Had a formula like:

If denominator <> 0 then
ToText(Truncate(Round(numerator / denominator * 100, 1), 1)) + "%"

But the truncate function doesn't seem to work properly. I'm always left with a value of something like 55.20 that is operated on by the ToText function. Don't know why the trailing zero isn't truncated.

Any help in accomplishing what I'm trying to do would be great.

Thanks in advance.
 
You shouldn't need truncate at all, and you can specify the decimals in totext:

If denominator <> 0 then
ToText(Round(numerator / denominator * 100, 1), 1) + "%" else
"N/A"

-LB
 
Great that worked!!! Thanks so much!!! Extremely helpful to know that the ToText function had the decimal specification option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top