Link to home
Start Free TrialLog in
Avatar of posseke
possekeFlag for Cabo Verde

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,
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

       Dim x As Double = 152.364484546401
        Dim y As String = x.ToString()
Avatar of posseke

ASKER

Doesn't seem to work.
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.
Avatar of posseke

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
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 ?
Avatar of posseke

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?
That's a possiblitie.
My double gave me: 152.364484546401
My string gave me: 152,364484546401
Avatar of posseke

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
Avatar of posseke

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
Avatar of posseke

ASKER

Upgrading this question to 250 points, it seems worth it :)
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial