"将字符串转换为十进制分隔符&QUOT的最佳方式;和","不敏感的方法吗? [英] Best way to convert string to decimal separator "." and "," insensitive way?
问题描述
应用程序处理与再present小数是来自不同文化背景的字符串。 例如1.1和1,1是相同的值。
我打了 Decimal.TryParse
标记的组合,但不能达到我想要的结果。毕竟1,1变成了11或0。
是否有可能转换这样的字符串转换为十进制的一行code,而不pre-替换,字符为。或 NumberFormat.NumberDecimalSeparator
?
你是如何处理这种情况?
感谢你在前进!
您有以下possibllities:
- 您知道文化
- 使用当前的文化环境,是安装了计算机
- 您让用户决定设置自己的文化 - 在你的程序>用户设置
- 您不知道文化
- 您必须决定这件事:你必须定义并记录你的决定
- 猜:你尝试解析,并试图解析,并尝试......直到你得到有效的号码
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
这篇关于"将字符串转换为十进制分隔符&QUOT的最佳方式;和","不敏感的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!