对文化格式进行双重解析 [英] Double parse with culture format

查看:75
本文介绍了对文化格式进行双重解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双精度数字作为字符串.数字是

I have a double number as string. The number is

202.667,40

202.667,40

哪个是202667.4

Which is 202667.4

我该如何解析该字符串以获取如下值:Double.Parse("202.667,40" ,?在这里是什么),或者任何其他获取该值的方法都很好.谢谢

How can I parse this string to get the value like: Double.Parse("202.667,40",?what here), or any other method to get the value would be great. Thanks

推荐答案

首先,您需要知道此数字来自哪种文化,然后:

First, you need to know which culture this number is from, then:

CultureInfo culture = new CultureInfo("de"); // I'm assuming german here.
double number = Double.Parse("202.667,40", culture);

如果要使用当前线程区域性进行解析,默认情况下,该区域性是当前用户的设置:

If you want to parse using the current thread culture, which by default is the one set for the current user:

double number = Double.Parse("202.667,40", CultureInfo.CurrentCulture);

这篇关于对文化格式进行双重解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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