|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to format financial value?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. Loyd,
This will do: int value = 45435; MessageBox.Show(value.ToString("C")); -- Show quoteCarsten Thomsen Enterprise Development with VS .NET, UML, AND MSF http://www.apress.com/book/bookDisplay.html?bID=105 Communities - http://community.integratedsolutions.dk "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. > 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 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") > > > 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") > > > > > > 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. > > > 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.... -- Show quoteThere 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. >> >> >> 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. > >> > >> > >> > > > >I don't see an easy way to do this. It seems you have to put together the thanks that gave me some idea ;-)> 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. |
|||||||||||||||||||||||