# How can i convert a decimal to the current locale of the browser ? [Answered]RSS

## 2 replies

Last post Dec 11, 2014 03:20 AM by gerrylowry

Member

156 Points

795 Posts

### How can i convert a decimal to the current locale of the browser ?

Hi ,

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 ?

thanks

Member

50 Points

15 Posts

### Re: How can i convert a decimal to the current locale of the browser ?

Please give a try like below,

Convert.ToDecimal(decimalNumber, CultureInfo.CreateSpecificCulture("hu-HU"))

Thanks,
Karthick.kb

Star

14297 Points

5882 Posts

### Re: How can i convert a decimal to the current locale of the browser ?

@robby32     sorry, at least for me, your question is unclear.

#### robby32

Convert.ToDecimal(0,78)

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:

`Console.WriteLine (Convert.ToDecimal(0,78));`

Error:

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);
/* 8 */ Console.WriteLine (numberAsDecimal);```

output:

```en-CA
0,78
0.78
hu-HU
0,78```

Notes:

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.

#### robby32

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"