将此字符串转换为十进制 [英] convert this string into decimal

查看:76
本文介绍了将此字符串转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来很简单,但是当我尝试实现这一目标时,我对格式化程序如何进行转换存有疑问,这是一些我需要转换为十进制的字符串示例

Sounds easy but when I tried to achieve i'm stock about how is the formatter to make this conversion this are some examples of strings that i need to convert to decimal

00.24
48.34
01.24

有人知道我该怎么做到吗?我这样尝试过

Does anybody know how can i Accomplish this?? I tried like this

try
{
   decimal x =  Convert.ToDecimal("00.24", );
   //Which formatter do I need to pass??
   decimal x =  Convert.ToDecimal("00.24", Formatter???);
}
Catch(Exception e)
{
    throw new Exception()
}

但是它不起作用,因为结果是24D,我需要0.24D

But It doesn't work because the result it's 24D and i need 0.24D

推荐答案

我怀疑您的系统语言不是英语,并且具有不同的数字格式设置规则。尝试将不变区域性作为格式提供者传递:

I suspect your system culture is not English and has different number formatting rules. Try passing the invariant culture as the format provider:

decimal d = Convert.ToDecimal("00.24", CultureInfo.InvariantCulture);

您还可以使用 Decimal.Parse

decimal d = Decimal.Parse("00.24", CultureInfo.InvariantCulture);

这篇关于将此字符串转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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