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!

StrToFloat with Thousand separators

Status
Not open for further replies.

JoeNg

Programmer
Apr 17, 2001
174
US
StrToFloat does not work with Thousand separators.

Is there a easy way to convert, say, '40,000.00' to real type?

Thanks

 
one very simple aproach :

//'40,000.00' - > '40000.00
StringReplace(YourfloatStr,',','',[rfReplaceAll);

cheers


--------------------------------------
What You See Is What You Get
 
Ah! Simple indeed.

Many thanks.
 
Another, marginally different variation:

StringReplace(YourFloatStr, ThousandSeparator, '',[ReplaceAll]);

Which version to prefer depends on if the offending string is always created on the same system as your application runs on or if you can be sure that the thousands separator always is a comma and not e.g. a space, or maybe even a dot from a spanish system. In the latter case you have an interesting task of determining which is the decimal separator (",") and which is the thousands separator (".")!
Cheers!

Jan-Christian
Old programmers never die,
they just slowly type away....
 
Thanks Jan-Christian

A very good point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top