从小数点后的地方移除结尾零防止double.Parse? [英] Preventing double.Parse from removing trailing zeros after decimal place?

查看:555
本文介绍了从小数点后的地方移除结尾零防止double.Parse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用double.Parse,似乎就喜欢串远离我正在转换字符串末尾的任何(不显着)为零。我想double.Parse保留到小数点后位。例如,下面是一些代码:

When using double.Parse, it seems to like to string away any trailing (insignificant) zeros from the string that I'm converting. I would like double.Parse to keep to places after the decimal. For example, here is some code:

tobereturned.MouseSensitivty = double.Parse(String.Format("{0:#.##}", tempstring[1]));
Debug.WriteLine("Converted " + String.Format("{0:#.##}", tempstring[1]) + " to " + tobereturned.MouseSensitivty);



调试器然后将写入

The Debugger then writes

4.00转换为4

所以好像double.Parse的的做有鬼这里。
附:在mouseSensitivity也是double类型,所以我不能做任何字符串操作。

So it seems like double.Parse is doing something fishy here. P.S. MouseSensitivity is also of the type double, so I can't do any string operations on it.

推荐答案

您的问题是毫无意义的。双打不要带有摆在首位的小数点后的地方。他们不存储任何看起来像远程内部一个等多项十进制表示。事实上,他们不存储任何国内甚至看起来像识别的文本。

Your question is meaningless. Doubles don't have "places after the decimal" in the first place. They don't store anything that looks remotely like a "decimal representation of a number" internally. In fact, they don't store anything internally that even looks like recognizable text.

据报道4,因为4.00是正好等于4。这是显示数字恰好四连没有小数部分为文本依据的数字转换为文本的默认规则。

It reports 4 because 4.00 is exactly equal to 4. It is displaying the number "exactly four with no fractional part" as text according to its default rules for converting numbers to text.

请阅读的this 。是的,这是漫长的,困难的,但它根本不可能使用浮点数类型的正确没有真正理解这种材料的 - 这不不管你使用,无论是语言。

Please read this. Yes, it is long, and difficult, but it is simply not possible to use floating-point numeric types properly without a real understanding of this material - and it doesn't matter what language you're using, either.

这篇关于从小数点后的地方移除结尾零防止double.Parse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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