Question formatting doubles

andrews

Well-known member
Joined
Nov 22, 2011
Messages
167
Programming Experience
5-10
Hi,
when I have a double variable f.e. v = 0.00003215478954...
i do not want to see all these decimals and I set round(v,6)
when I put this in messagebox.show i see 3.2E-05 but I want to see 0.000032
I have a solution but is this the shortest ?
v = v*10^6
v = floor(v)
v = v/10^6
Thanks for any response
 
Hi,

Here are two examples of how to do this. You can either use a Decimal type for the value and use Math.Round or if you want to keep the value as a Double type then you can Format the ToString method. i.e:-

VB.NET:
Dim x As Decimal = 0.00003215478954D
MsgBox(Math.Round(x, 6))
 
Dim y As Double = 0.00003215478954
MsgBox(y.ToString("0.000000"))

Hope that helps.

Cheers,

Ian
 
Back
Top