字符串到小数的转换:点分离,而不是逗号 [英] String to decimal conversion: dot separation instead of comma

查看:184
本文介绍了字符串到小数的转换:点分离,而不是逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框读取的字符串。它包含小数点的逗号。

I have a string read from a textbox. It contains a comma for decimal separation.

NumberFormatInfo.CurrencyDecimalSeparator 设置为(逗号),但是当我的字符串转换为十进制 Convert.ToDecimal(myString的); 我获得十进制点单独的值

I have NumberFormatInfo.CurrencyDecimalSeparator set to , (comma) but when I convert the string to decimal Convert.ToDecimal(mystring); I obtain a dot separate value for decimal.

例如:

decimal a=Convert.ToDecimal("1,2345"); ----> decimal is 1.2345



我曾尝试也:

I have tried also:

double a=Convert.ToDouble("1,2345"); 



但点小数再次

but dot for decimal again

推荐答案

感谢所有的答复。

由于我必须写在一个XML文件中我发现问题的十进制数。在讨论中,我已经学会了十进制值的XML文件标准使用点,这是文化的独立。
所以我的解决办法是写点分十进制数的XML文件,并从同一个XML文件转换成字符串readed mystring.Replace(,);
由于阿加特作为建议,研究问题的XML上下文和ΕГИІИО,因为我不知道Visual Studio的不尊重文化设置,我有我的代码。

Because I have to write a decimal number in a xml file I have find out the problem. In this discussion I have learned that xml file standard use dot for decimal value and this is culture independent. So my solution is write dot decimal number in a xml file and convert the readed string from the same xml file mystring.Replace(".", ","); Thanks Agat for suggestion to research the problem in xml context and Ε Г И І И О because I didn't know visual studio doesn't respect the culture settings I have in my code.

这篇关于字符串到小数的转换:点分离,而不是逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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