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!

Converting a Float to text with conditions 1

Status
Not open for further replies.

cburns70

IS-IT--Management
Sep 12, 2006
19
US
Crystal 10, Sql 2005

I have float value I need changed to text. Here's the catch; the text that is displayed cannot have any extra trailing zeros. Example:

float = .0023 text has to equal .002
float = .002 text has to equal .002
float = .01 text has to equal .01
float = .1 text has to equal .1
float = 1.1 text has to equal .1
float = 1 text has to equal 1
and so on....

If I try to display the float on my report with out converting it to a string I will have the trailing zeros, eg. .002 will be .0020. But, I really need it as a string, because based on another value on the report, I have to display a string in this column.

I can convert to a string but i get the same problem, either the value is cut off or it has a trailing zero. I cant do a ToText({table.float},4) because I'll still get trailing zeros. Since the value is a float I could have up to 7 decimal places. Does anybody have any suggestions? Thanks in advance
 
How do you logically determine how many decimals to have for each value?

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If the phone doesn't ring, it's me".....Jimmy Buffet
 
Try:

stringvar x := totext({table.float},7,"");
if val(right(x,7)) = 0 then totext(val(x),0) else
if val(right(x,6)) = 0 then totext(val(x),1) else
if val(right(x,5)) = 0 then totext(val(x),2) else
if val(right(x,4)) = 0 then totext(val(x),3) else
if val(right(x,3)) = 0 then totext(val(x),4) else
if val(right(x,2)) = 0 then totext(val(x),5) else
if val(right(x,1)) = 0 then totext(val(x),6) else
totext(val(x),7)

-LB
 
Thanks Lbass that worked perfectly.

dgillz, the data comes from a Laboratory Information Management System. The trailing zeros had some signficance to them, but I'm not sure why.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top