"将字符串转换为十进制分隔符&QUOT的最佳方式;和","不敏感的方法吗?转换为、字符串、敏感、方式

由网友(矜持的血)分享简介:应用程序处理与再present小数是来自不同文化背景的字符串。例如1.1和1,1是相同的值。我打了 Decimal.TryParse 标记的组合,但不能达到我想要的结果。毕竟1,1变成了11或0。 是否有可能转换这样的字符串转换为十进制的一行code,而不pre-替换,字符为。或 NumberFormat.Numbe...

应用程序处理与再present小数是来自不同文化背景的字符串。 例如1.1和1,1是相同的值。

我打了 Decimal.TryParse 标记的组合,但不能达到我想要的结果。毕竟1,1变成了11或0。

是否有可能转换这样的字符串转换为十进制的一行code,而不pre-替换,字符为。或 NumberFormat.NumberDecimalSeparator

你是如何处理这种情况?

感谢你在前进!

解决方案

您有以下possibllities:

您知道文化 使用当前的文化环境,是安装了计算机 您让用户决定设置自己的文化 - 在你的程序>用户设置 您不知道文化 您必须决定这件事:你必须定义并记录你的决定 猜:你尝试解析,并试图解析,并尝试......直到你得到有效的号码 excel数字分隔符怎么用 excel数字分隔符设置方法

Application deals with strings that represent decimals that come from different cultures. For example "1.1 and "1,1" is the same value.

I played with Decimal.TryParse flags combinations but couldn't achieve the result I want. "1,1" became "11" or "0" after all.

Is it possible to convert such strings to decimal in one line of code without pre-replacing "," char to "." or playing with NumberFormat.NumberDecimalSeparator ?

How do you handle such situations?

Thank you in advance!

解决方案

You have the following possibllities:

You know the culture

Use the current Culture setting, for which the computer is installed You let the user decide to set his culture -> user settings in your program

You do not know the culture

You must decide about it: you have to define and document your decision Guess: you try to parse, and try to parse, and try to ... until you get valid numbers

阅读全文

相关推荐

最新文章