Last post Dec 11, 2014 03:20 AM by gerrylowry
Dec 10, 2014 10:18 PM|robby32|LINK
if i have the following decimal 0,78 (Hungarian format with comma separator)
when i do Convert.ToDecimal(0,78) it gives me back 0.78 not the correct format i am after 0,78.
How can i overcome this ?
Dec 10, 2014 11:05 PM|karthick.kb|LINK
Please give a try like below,
Dec 11, 2014 03:20 AM|gerrylowry|LINK
@robby32 sorry, at least for me, your question is unclear.
http://msdn.microsoft.com/en-us/library/hf9z3s65(v=vs.110).aspx`'Convert.ToDecimal Method (String)"
0,78 as a parameter is not a valid overload for Convert.ToDecimal
This is not legal c# .NET Framework:
The best overloaded method match for 'System.Convert.ToDecimal(object, System.IFormatProvider)' has some invalid arguments
Argument 2: cannot convert from 'int' to 'System.IFormatProvider'
in Europe, North America's decimal point is likely to be a comma instead.
However, the comma is not stored internally:
/* 1 */ Console.WriteLine (Thread.CurrentThread.CurrentCulture.ToString());
/* 2 */ String numberAsString = "0,78"; // this is a European format
/* 3 */ Decimal numberAsDecimal = Convert.ToDecimal(numberAsString, System.Globalization.CultureInfo.CreateSpecificCulture("hu-HU"));
/* 4 */ Console.WriteLine (numberAsString);
/* 5 */ Console.WriteLine (numberAsDecimal);
/* 6 */ Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("hu-HU");
/* 7 */ Console.WriteLine (Thread.CurrentThread.CurrentCulture.ToString());
/* 8 */ Console.WriteLine (numberAsDecimal);
Line 1 prints the current culture, in my case Canadian English.
Line 2 creates a string containing the European version of 78 / 100 expressed as a string with a comma.
Line 3 converts this to a type Decimal; for this to not cause a run time error, we also tell Convert.Decimal that we are working with a Hungarion style number.
Line 4 for my locale shows this stored number as 0.78 which prints with a period because of my locale.
Line 6 changes my culture.
Line 8 prints 0,78 because of the change made in line 6.
How can i convert a decimal to the current locale of the browser ?
what do you mean by browser? You can not know the locale of the browser ... the locale of the browser is not passed to your web server as a part of the request.
Even if you have a text fields for city and language and i tell my city is Québec and my language is French, you can not assume that my locale is fr-CA.
http://msdn.microsoft.com/en-us/library/bb975829.aspx 'Language, Locales, and Cultures in the .NET Compact Framework for Xbox 360"
robby32, what exactly is your issue? please clarify.