all groups > dotnet framework > october 2005 >
You're in the

dotnet framework

group:

parsing of a formatted currency string


parsing of a formatted currency string shriop
10/31/2005 1:01:45 PM
dotnet framework:
I'm looking for a nifty way of parsing a numeric value back out of a
previously formatted currency string. Even if it's long winded
involving grabbing symbols from the current locale. I'm trying to build
some functionality for other developers to be able to read in data from
flat files, and I don't want to force my logic to be only US specific.
I was hoping to make it as open as possible to handle whatever kind of
formats they've created. Any help would be appreciated.

Bruce
Re: parsing of a formatted currency string shriop
10/31/2005 2:26:27 PM
Found it.

double returnVal = Double.Parse(money, NumberStyles.Currency);

[quoted text, click to view]
Re: parsing of a formatted currency string Mihai N.
10/31/2005 10:16:55 PM
[quoted text, click to view]

This is one of the trickiest things.

Because what most routines/libraries assume is that the currency and currency
format are tied directly to the locales.
According to this, if the locale is French/France, then "1 234 567,89 €"
And if the locale is English/U.S.A., then "$1,234,567.89"

But currency is not tied to a locale. Only currency format is.
So you can have e price in dollars formated in a French/France locale:
"1 234 567,89 dollar des États-Unis"

There are many other traps here. For instance $ is used as currency symbol in
many other countries, some not even named dolar (ie the Mexican Peso).

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
AddThis Social Bookmark Button