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!

Trailing Zeros 1

Status
Not open for further replies.

sjc1956

Technical User
Jan 14, 2004
19
I work in healthcare and we are having a trailing zero problem. I need to remove the decimal point and the zeros from a medication dose strength (dose_str). I need 500 MG instead of 500.00 mg. But if there is a dose that's 500.25 then I need that to remain. The 500.00 is a string.
Let me know if you need more info. Thanks.
 
Do you want to include the "mg" as part of the formula? If so, try this:

If Int(Val({Table.Field})) <> Val({Table.Field}) Then
{Table.Field} + " mg"
Else
ToText(Val({Table.Field}), 0, "") + " mg";

The logic here is that if the integer portion of the string doesn't equal the true value of the string, then the decimal portion is kept. Otherwise, the decimal portion is truncated.

-dave
 
Thank you very much, that seems to work. I did leave off the "mg" because that's in another field. However, another question: We are unsure the number of significant digits after the decimal. For example, we my have 50.50 or 50.55. When printing we are wanting to show 50.5 or 50.55. (The trailing zeros should not show)
Thanks again.
 
Will there always be a decimal place in the string, and are there any cases where the precision of the decimal portion is > 2 (e.g. .0125)?

-dave
 
Yes there will always be a decimal point. The precision is always 2.
 
This should take care of it:

StringVar Decimal := Split({Table.Field},".")[2];
if Decimal[2] <> "0" then
ToText(Val({Table.Field}), 2, "")
else if Decimal[1] <> "0" then
ToText(Val({Table.Field}), 1, "")
else
ToText(Val({Table.Field}), 0, "")

-dave
 
Hello !

This is amazing, but I need the same thing. I used both of your suggestions (vidru) To get rid of trailing zeros without rounding off the decimal.

If Int(Val({Table.Field})) <> Val({Table.Field}) Then
{Table.Field} + " mg"
Else
ToText(Val({Table.Field}), 0, "") + " mg";

And of course replaced my own table name. I am getting an error "A string is required here" just before the first table field replacement. Is there somthing else I should be entering there? I am using Crystal 7.5?

Thank You !

Jan

Jan1229
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top