Rounding Question

S

Samuel

The first line of code produces the value of 1.92 while the second 1.18

WHY???



Dim d As Double = Math.Round(1.925, 2)

Dim d1 As Double = Math.Round(1.175, 2)
 
J

Jack Jackson

The first line of code produces the value of 1.92 while the second 1.18

WHY???



Dim d As Double = Math.Round(1.925, 2)

Dim d1 As Double = Math.Round(1.175, 2)

Because the digit before the 5 in 1.925 is even, and the digit before
the 5 in 1.175 is odd.

See the Remarks section of the Math.Round documentation for details,
and for ways to control what kind of rounding is done.

<http://msdn2.microsoft.com/en-us/library/zy06z30k.aspx>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Single v. Double Help 1
Rounding Problem 5
Decimals 7
Can't to real Double to Integer cast in VB.NET?!? 20
Math problem using a Double 6
DirectCast - Why is this not working? 4
Rounding 2
Rounding issue 4

Top