how to format financial value?

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I would like to format financial value with something as simple as:
string.Format("{0:$#.###.00}", value)

but instead of hardcoding the format string I would like to use the system
one.
I found the NumberFormatInfo but I can't find how to get the currency format
string from it....

Any tip?
 
yep.. this is... not good... (I need a culture independant string for my
culture.. do you see what I mean?

mmh.. what I want is: I want a local dependant currency format when I create
my file. But then I want to keep this format (or edit so) so even if the
file is view by an other user in an other country the price in $ stay in
dollar.

say:
you create car database.
Table: Parameter
Key Value
========
Currency $#,###.00

Table Car
Name Value
=========
Holden 20000

now I want the holden price to be displayed as $20.000
if the file is viewed by a french guy and suddenly become
20 000e it will be completely inacurrate!

I would like to avoid the solution of storing the file culture and do
everyhing i this culture.instead I would like to store the currency format
(initialized to from current local) and be able to edit it.

My problem is how do I get the currency formt from NumberInfo (I don't mean
"C" but "$#,###.00")
 
try to set the
Systme.Threading.Thread.CultureInfo.NumberFormat.CurrencySymbol to "$"
this will set the currency symbol regardless of where the user from

Cheers,
Ivan Wong
 
Sorry, you should set this
System.Threading.Thread.CurrentCulture.NumberFormat.CurrencySymbol to "$"

Cheers,
Ivan Wong
 
I think you would have to save the values of just about every property of the
instance of NumberInfo you are using to store the values. Maybe you can
serialize the NumberInfo instance to the file and deserialize it again when
the file is loaded? (NumberInfo is serializable).

HTH, Jakob.
 
MY problem Jokab is how to use a NumberFormatInfo to format my value myself?
they have so many value....
I'm looking just fo a simple fromating string....
 
I don't see an easy way to do this. It seems you have to put together the
format string yourself from the given properties of the NumberFormatInfo.
Again, one solution might be to serialize the entire NumberFormatInfo to your
file. Later on you can deserialize it and format your string the right way:

double d = ...;
NumberFormatInfor nfo = Deserialize();
string s = d.ToString("C", nfo);

I am sorry I am not able to help you but I don't see an easy solution to
your problem.

Regards, Jakob.
 
I don't see an easy way to do this. It seems you have to put together the
format string yourself from the given properties of the NumberFormatInfo.
Again, one solution might be to serialize the entire NumberFormatInfo to
your
file. Later on you can deserialize it and format your string the right
way:

double d = ...;
NumberFormatInfor nfo = Deserialize();
string s = d.ToString("C", nfo);

I am sorry I am not able to help you but I don't see an easy solution to
your problem.
thanks that gave me some idea ;-)
 
Back
Top