有一个奇怪的行为,双重解析字符串输入? [英] there is a strange behaviour double parse string input?
本文介绍了有一个奇怪的行为,双重解析字符串输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试读一些excel文件和转换一些字符串列在数据库保存。但我面对面一些双解析错误:双重结果= double.Parse(1,15);
结果:1.149999999999 ....我不希望看到这一点。我想double结果= double.Parse(1,15);结果= 1.15
静态无效的主要(字串[] args)
{
的NumberStyles款式;
的IFormatProvider提供商;
曲风= NumberStyles.Float;
提供商= CultureInfo.CreateSpecificCulture(TR-TR);
字符串测试=1.15;
双重结果= double.Parse(测试,风格,CultureInfo.CreateSpecificCulture(TR-TR));
Console.WriteLine(result.ToString());
}
}
解决方案
使用为DB的小数
的数据类型和应用,如果你需要高精度的数据类型。
i try to read some excel file and converting some string column to save in db. BUT i face to face some double parse error: double result = double.Parse( 1,15); result: 1.149999999999.... i dont want to see this. i want double result = double.Parse( 1,15); result = 1.15
static void Main(string[] args)
{
NumberStyles styles;
IFormatProvider provider;
styles = NumberStyles.Float;
provider = CultureInfo.CreateSpecificCulture("tr-TR");
string test = "1,15";
double result = double.Parse(test, styles, CultureInfo.CreateSpecificCulture("tr-TR"));
Console.WriteLine(result.ToString());
}
}
解决方案
Use the decimal
data type for DB and Application if you need the high precision data types.
这篇关于有一个奇怪的行为,双重解析字符串输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文