Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET Converting Double Value to String = Precision loss

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?

like image 698
user2776069 Avatar asked Sep 03 '25 04:09

user2776069


1 Answers

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")
like image 166
ɐsɹǝʌ ǝɔıʌ Avatar answered Sep 05 '25 00:09

ɐsɹǝʌ ǝɔıʌ