posseke
asked on
Convert double to string without loss of digits after zero
Hello,
I'm developing in VB.NET, and confronted with this idiotic problem.
I have a double variable i need to convert to a string.
dim x as double = 152.364484546401
When using Cstr() to convert this double to a string, i lose my last ten digits after zero, leaving me with 152,36.
How can i prevent this kind of truncation?
Thanks,
I'm developing in VB.NET, and confronted with this idiotic problem.
I have a double variable i need to convert to a string.
dim x as double = 152.364484546401
When using Cstr() to convert this double to a string, i lose my last ten digits after zero, leaving me with 152,36.
How can i prevent this kind of truncation?
Thanks,
ASKER
Doesn't seem to work.
Seems such a simple thing, but it turns out wrong every time I try something to solve it...
Seems such a simple thing, but it turns out wrong every time I try something to solve it...
I tested here, and my string contains the same as the double.
ASKER
I tested too, in Immediate window:
1.5454545454545.ToString :
gives the result wanted
but when working with a double variable, it's not working anymore:
mydoublevar.Tostring
1.5454545454545.ToString :
gives the result wanted
but when working with a double variable, it's not working anymore:
mydoublevar.Tostring
Very strange. I created a new console-application and added those 2 statements and added a breakpoint at the latest line and I saw that it went good.
Did you only try it on the immediate window or also in code with a breakpoint ?
Did you only try it on the immediate window or also in code with a breakpoint ?
ASKER
I tried it In immediate window and through code with a breakpoint.
I'm not some noob in programming so this is really driving me nuts to be stuck at this kind of problem.
Is this Culture related perhaps?
I'm not some noob in programming so this is really driving me nuts to be stuck at this kind of problem.
Is this Culture related perhaps?
That's a possiblitie.
My double gave me: 152.364484546401
My string gave me: 152,364484546401
My double gave me: 152.364484546401
My string gave me: 152,364484546401
ASKER
Lol this sucks, what options do I have to rule out any Culture related dependencies?
Perhaps this can help you
Double..::.ToString Method (IFormatProvider)
http://msdn.microsoft.com/en-us/library/shxtf045.aspx
Double..::.ToString Method (IFormatProvider)
http://msdn.microsoft.com/en-us/library/shxtf045.aspx
ASKER
Thanks for the help, but nothing new there.
As you can see in the file attached, my double variable contains every digit i need, but when performing the ToString after it, it freaks out.
test.JPG
As you can see in the file attached, my double variable contains every digit i need, but when performing the ToString after it, it freaks out.
test.JPG
ASKER
Upgrading this question to 250 points, it seems worth it :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim y As String = x.ToString()