[c#]十进制逗号或点 [英] [c#] decimal comma or dot

查看:111
本文介绍了[c#]十进制逗号或点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个应用程序并将其发送给我的朋友和教授。教授正在使用matlab,mathematica,...所以windows中的十进制字符从逗号(,)更改为点(。),并得到错误的结果。

如何制作使用字符的应用程序对于在控制面板中设置的小数 - > Windows中的区域设置?因此,如果用户有小数点,则插入点,如果逗号,则插入逗号,在这两种情况下,字符表示十进制。

我尝试过:

 a = double.Parse(textBox1.Text,System.Globalization.NumberStyles.Number,System.Globalization.NumberFormatInfo。 CurrentInfo); 



但它不起作用。



如何解决这个问题?

解决方案

你是否在没有数字格式的情况下尝试过它?

 a = double.Parse(textBox1.Text,System.Globalization.NumberFormatInfo.CurrentInfo ); 





另请查看此处的示例:

http://msdn.microsoft.com/en-us/library/t9ebt447.aspx [ ^ ]



祝你好运!


尽早将应用程序的文化设置为en-US,例如在 public static int Main(string [] args)

 Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo (  en-US); 
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo( en-US);


I`ve made an app and send it to my friends and professor. Professor is using matlab, mathematica,... so the decimal character in windows was changed from comma (,) to dot (.), and gets wrong results.
How to make the app that uses character for decimal which is set in control panel --> regional setting in windows? So if user has dot for decimal then insert dot if comma then insert comma, and in both cases characters means decimal.
I tried with:

a = double.Parse(textBox1.Text, System.Globalization.NumberStyles.Number, System.Globalization.NumberFormatInfo.CurrentInfo);


but it does not work.

How to fix this?

解决方案

Did you try it without numberformat?

a = double.Parse(textBox1.Text, System.Globalization.NumberFormatInfo.CurrentInfo);



Also check the example here:
http://msdn.microsoft.com/en-us/library/t9ebt447.aspx[^]

Good luck!


Set the culture of your application to "en-US" early, e.g. in public static int Main(string[] args):

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");


这篇关于[c#]十进制逗号或点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆