Link to home
Start Free TrialLog in
Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden

asked on

precision issue in C#.NET double value.

Hi there;

I have an issue in my C#.NET project.

I have a variable having a double value and when I debug, I can see it preserves its double value, but in console, it gives the trimmed value.

This only happens for e.g. 1.0, not 1.2 or so.

The output in the console for 1.0 is 1 where as for others like 1.2, the output is still 1.2.

The line I am using is:
 Console.WriteLine(doubleval.ToString());

So, what am i missing?

Regards.
ASKER CERTIFIED SOLUTION
Avatar of esolve
esolve
Flag of South Africa 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
SOLUTION
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
Avatar of jazzIIIlove

ASKER

Hi there;

It seems pretty trivial but the problem persists:

Assume the followings are double type values:
I want to see exactly the same values written here, no additional precision, no trimming or rounding.

0.9
5.1
0.17
0.0
0.15
0.15
0.9
1.1
0.92 -> while printing, I failed in this, it simply rounds to 0.9 exactly.
0.5
0.2
1.0
1.2

Your current recommendations are not completely work in every above case.

What to do? I am needless to say using Console.WriteLine(..

Regards.
I think my algorithm is false. I will come back.

Regards.
SOLUTION
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
I found my algorithm is false but I am not deleting the question.