DE decimal changing to comma value issue in asp.net

I am using german UI Culture in my asp.net application. I am changing my application's UI culture based on the language selected in the dropdown, on dropdown selected index change i am using this code

Thread.CurrentThread.CurrentCulture = new CultureInfo(this.lstLanguage.SelectedValue);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.lstLanguage.SelectedValue);

the Dropdown is as below

<asp:DropDownList cssClass="ddllanguage" ValidationGroup="b" runat="server" ID="lstLanguage" AutoPostBack="True"  OnSelectedIndexChanged="LstLanguage_SelectedIndexChanged" meta:resourcekey="lstLanguage">                    
  <asp:ListItem Value="en-US" Text="English" meta:resourcekey="ListItemResource2" ></asp:ListItem>
  <asp:ListItem Value="de-DE" Text="Deutsch" meta:resourcekey="ListItemResource3"></asp:ListItem>
</asp:DropDownList>

My problem is after changing the language to de-DE all the decimal values in my application are being changed as comma, all the decimal number like 5.12 is coming as 5,12 all the decimal values are changed to comma. How to get decimal values as it is without comma.


you can change number format info as per below code

Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";

try below code for parsing the decimal values as per culture.

string str = "50,3";
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
double d = double.Parse(str, Thread.CurrentThread.CurrentCulture.NumberFormat);

it gives result d = 50.3


In german culture Decimal is denoated by ","

German culture uses "." as a group separator and "," as the decimal separator

Refer wiki link


Thread.CurrentUICulture is intended to be used for User Interface, it's the language used to display text, orientation and so on.
Thread.CurrentCulture is intended to be used for parsing/formatting stuffs. Date and time, numbers and string comparison (for example).

If you want to change only UI language (and to keep everything else with the culture of your web server) you have to modify only Thread.CurrentUICulture .

链接地址: http://www.djcxy.com/p/75110.html

上一篇: Double.Parse不能保留逗号

下一篇: DE十进制在asp.net中更改为逗号值问题