在c#中如何处理双重解析中的文化? [英] how to handle culture in double parsing in c#?

查看:152
本文介绍了在c#中如何处理双重解析中的文化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解析双打时,我有一个关于如何处理文化的问题。
在系统中,来自各种服务器的价格信息汇集在一起​​。
然而,输入的数据在文化上是不同的。
二百五十美分为:

2.000.000,50

2,000,000.50

2000000.50

2000000,50



是否有一种通用的方式来处理这些各种类型的输入?

解决方案

不,没有通用的方式。您需要知道 double 的格式化或所有服务器需要以单一格式发送的文化,例如 InvariantCulture



如果你猜这种文化,不同的文化使用不同的小数分隔符,分组分隔符等,你会发现一个坏消息,所以你不能。 p>

如果你猜,请参考这个可能会出错的地方 / p>

I have a question about how to handle culture while parsing doubles. In a system price information from various servers comes together. However the data thats given as input varies in culture. two million and fifty cents is given as :
"2.000.000,50"
"2,000,000.50"
"2000000.50"
"2000000,50"

is there a generic way to handle these various types of input ?

解决方案

No, there is no generic way. You either need to know what culture the double was formatted or all the servers need to send in a single format, say InvariantCulture.

If you guess the culture, there's a bad news waiting for you as different cultures use different decimal separator, group separator etc. So you can't.

Refer this to foresee what can go wrong if you guess.

这篇关于在c#中如何处理双重解析中的文化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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