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

Format Float 1

Status
Not open for further replies.

sharook

Programmer
Aug 22, 2006
21
US
Well, I'm not sure this can be done, but I'll throw it out there and see what you guys think. I have a float value that is something like 58483.97. I format it as follows %5.0f. However, when I do this, it rounds up to 58484. I don't want this to happen. I need it to clip the two digits after the decimal and leave it as 58483.

Thank you
 
Convert the number to a string, drop the last 3 characters, and convert back to an integer?

numtostr - strtonum

 
Unfortunately it looks like this is by design, I found the below comment in the Formatting Text and Data help topic:

Since precision specifies the maximum number of digits, it may cause truncation of strings or rounding of floats.

 
Ya, that is why I thought it couldn't be done because I read the same thing in the good old purple book. However, I created a workaround and it works:

ftoa TelPassword TelPassFinal

strfmt UserNameStr "**********^M"
strfmt PassWordStr "%5.5s^M" TelPassFinal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top