Home All Groups Group Topic Archive Search About

how to format financial value?

Author
2 Oct 2005 10:11 AM
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?

--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.

Author
3 Oct 2005 5:41 AM
CT
Loyd,

This will do:

int value = 45435;
MessageBox.Show(value.ToString("C"));


--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

Show quote
"Lloyd Dupont" <l*@NewsAccount.galador.net> wrote in message
news:er7demzxFHA.2652@TK2MSFTNGP14.phx.gbl...
>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?
>
> --
> There are 10 kinds of people in this world. Those who understand binary
> and those who don't.
>
Author
3 Oct 2005 6:27 AM
Lloyd Dupont
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")
Author
3 Oct 2005 7:20 AM
Ivan Wong
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

Show quote
"Lloyd Dupont" wrote:

> 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")
>
>
>
Author
3 Oct 2005 7:25 AM
Ivan Wong
Sorry, you should set this
System.Threading.Thread.CurrentCulture.NumberFormat.CurrencySymbol to "$"

Cheers,
Ivan Wong

Show quote
"Ivan Wong" wrote:

> 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
>
> "Lloyd Dupont" wrote:
>
> > 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")
> >
> >
> >
Author
3 Oct 2005 3:58 PM
Jakob Christensen
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.
Show quote
"Lloyd Dupont" wrote:

> 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?
>
> --
> There are 10 kinds of people in this world. Those who understand binary and
> those who don't.
>
>
>
Author
4 Oct 2005 8:24 AM
Lloyd Dupont
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....

--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
Show quote
"Jakob Christensen" <j**@REMOVEpension.dk> wrote in message
news:E0F31FE2-03C7-475A-865F-500304FF56A1@microsoft.com...
>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.
> --
> http://www.dotninjas.dk
> http://www.powerbytes.dk
>
>
> "Lloyd Dupont" wrote:
>
>> 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?
>>
>> --
>> There are 10 kinds of people in this world. Those who understand binary
>> and
>> those who don't.
>>
>>
>>
Author
4 Oct 2005 9:36 AM
Jakob Christensen
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.
Show quote
"Lloyd Dupont" wrote:

> 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....
>
> --
> There are 10 kinds of people in this world. Those who understand binary and
> those who don't.
> "Jakob Christensen" <j**@REMOVEpension.dk> wrote in message
> news:E0F31FE2-03C7-475A-865F-500304FF56A1@microsoft.com...
> >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.
> > --
> > http://www.dotninjas.dk
> > http://www.powerbytes.dk
> >
> >
> > "Lloyd Dupont" wrote:
> >
> >> 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?
> >>
> >> --
> >> There are 10 kinds of people in this world. Those who understand binary
> >> and
> >> those who don't.
> >>
> >>
> >>
>
>
>
Author
4 Oct 2005 12:48 PM
Lloyd Dupont
>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 ;-)

AddThis Social Bookmark Button