VB.NET Converting Double Value to String = Precision loss

double, string, vb.net

Solution

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")

Problem

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?

Original source