简体   繁体   English

将字符串转换为双精度,明确使用句点作为小数点

[英]Convert String to Double, Explicitly Using Period as Decimal Point

One of my software's functions is to convert numeric strings into double datatype. 我的软件的功能之一是将数字字符串转换为double精度数据类型。 I want to explicitly indicate the use of period (.) as a decimal point. 我想明确指出使用句点(。)作为小数点。 Thus, no matter the language settings of the user's system, it will correctly read a period-separated decimal. 因此,无论用户系统的语言设置如何,它都会正确读取以句点分隔的小数。 I believe the solution is to use the IFormatProvider argument in the Convert.ToDouble() function. 我相信解决方案是在Convert.ToDouble()函数中使用IFormatProvider参数。 I am unsure how to do this. 我不确定该怎么做。

Example: String: "3.14" Double: 3.14 示例:字符串:“ 3.14”双精度:3.14

Use CultureInfo.InvariantCulture while parsing. 解析时使用CultureInfo.InvariantCulture

double d = double.Parse("3.14", CultureInfo.InvariantCulture);

See: CultureInfo.InvariantCulture Property 请参阅: CultureInfo.InvariantCulture属性

The invariant culture is culture-insensitive; 不变文化对文化不敏感; it is associated with the English language but not with any country/region. 它与英语相关联,但与任何国家/地区无关。

double.Parse(yourString, CultureInfo.InvariantCulture)

编辑:或看到此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM