gpt4 book ai didi

c# - 将此字符串转换为十进制

转载 作者:太空宇宙 更新时间:2023-11-03 17:33:25 25 4
gpt4 key购买 nike

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

00.24
48.34
01.24


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

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

最佳答案

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

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


您也可以使用 Decimal.Parse

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

关于c# - 将此字符串转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10507759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com