VB.Net 字符串加倍
为什么当我使用 Dbl() 将值为“22.882”的字符串转换为 double 时,它会丢失精度并转换为 2288.2?
我必须使用双精度,因为我正在使用 System.Web.UI.WebControls.Unit 的构造函数 (请参阅http://msdn.microsoft.com/en-us/library/ ctewx7ch.aspx)。
Why is it that when I convert a string with value "22.882" to double, using Dbl() it loses precision and is converted to 2288.2?
I have to use a double since I'm using the constructor of System.Web.UI.WebControls.Unit
(see http://msdn.microsoft.com/en-us/library/ctewx7ch.aspx).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有明显的理由说明为什么会将值更改为
2288.2
,但如果它实际上最终为22882.0
,那么您只是使用了一种不使用句点的区域性小数点分隔符。您只需指定一种使用句点作为小数点分隔符的区域性:
There is no apparent reason why it would change the value to
2288.2
, but if it actually ends up as22882.0
then you are just using a culture that doesn't use period as decimal separtor.You just have to specify a culture that does use the period as decimal separator:
尝试
Double.TryParse(...)
。
Try
Double.TryParse(...)
.