Board index » delphi » Convert String to Currency

Convert String to Currency

I am using Delphi 6 Enterprise and I have a string with a value of
'$17,000.000'.  I want to save this string in a database field (using ADO
with MS Access 2000) that has an MS Access type of Currency.  All of the
conversion routines I try give me something similar to this.

"...$17,000.00 is not a valid floating point value for field
PurchasePrice..."

I've used a bunch of combinations like the following.

Fields[b].AsString    := comma.Strings[b];
Fields[b].AsCurrency  := StrToCurr(comma.Strings[b]);
Fields[b].AsCurrency  := StrToFloat(comma.Strings[b]);

Any help would be greatly appreciated.

Kevin

 

Re:Convert String to Currency


Quote
>"...$17,000.00 is not a valid floating point value for field
>PurchasePrice..."

>I've used a bunch of combinations like the following.

>Fields[b].AsString    := comma.Strings[b];
>Fields[b].AsCurrency  := StrToCurr(comma.Strings[b]);
>Fields[b].AsCurrency  := StrToFloat(comma.Strings[b]);

You will need to parse out the Currency symbol and Thousands separator
characters before you can convert your string to currency.
You can use StringReplace to do that

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Convert String to Currency


Thanks Brian.  I had come to that conclusion but wanted to know if there was
an automatic way to make it happen.  Thanks for confirming it for me.

Kevin

"Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
news:8dhd9ugbqvh8toed54jk2jis0qj8hfvbsr@4ax.com...

Quote

> >"...$17,000.00 is not a valid floating point value for field
> >PurchasePrice..."

> >I've used a bunch of combinations like the following.

> >Fields[b].AsString    := comma.Strings[b];
> >Fields[b].AsCurrency  := StrToCurr(comma.Strings[b]);
> >Fields[b].AsCurrency  := StrToFloat(comma.Strings[b]);

> You will need to parse out the Currency symbol and Thousands separator
> characters before you can convert your string to currency.
> You can use StringReplace to do that

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Other Threads