VB.NET Converting Double Value to String = Precision loss
19,128
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")
Related videos on Youtube
Author by
user2776069
Updated on June 30, 2022Comments
-
user2776069 about 2 years
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?
-
Adriano Repetti over 10 yearsProblem is only in your format string, ask formatter to pick right representation with
value.ToString("R")
and you'll got it.
-