VB.NET将Double Value转换为String =精度损失 [英] VB.NET Converting Double Value to String = Precision loss

查看:811
本文介绍了VB.NET将Double Value转换为String =精度损失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在VB.NET中有一个这样的双重值:

  Dim值= 9.729000000000001 

转换成字符串时,我得到这个:

  value.tostring()9.729

我尝试添加格式: / p>

  value.tostring(0.00000000000000)

但它没有起作用(我输了1)。



如何保留所有的数字? >

解决方案

这是记录 here here



尝试这个

  Dim值As Double = 9.729000000000001 
Dim strText As String = value.ToString(G17)

或这个

  Dim值As Double = 9.72900000000000 1 
Dim strText As String = value.ToString(R)


Hello I have a double value like this in VB.NET:

Dim value = 9.729000000000001

When converting to string, I get this:

value.tostring() "9.729"

I try to add formatting:

value.tostring("0.00000000000000")

But it did not work (I lose the ending 1).

How can I keep all of my digits?

解决方案

This is documented here and here

Try this

Dim value As Double = 9.729000000000001
Dim strText As String = value.ToString("G17")

Or this

Dim value As Double = 9.729000000000001
Dim strText As String = value.ToString("R")

这篇关于VB.NET将Double Value转换为String =精度损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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