math.round problem

T

Test User

Hi all,

I have learnt that if I want to round 0.5 to an integer the result should be
1, This is also the case if I do it in SQL server 2000, but if I do it in
VB.NET the result will be 0.

Other rounding results: 1.5 = 2 in SQL and 2 in VB.NET which I believe is
corrrect
2.5 = 3 in SQL and 2 in VB.NET which I believe is wrong.

Can anybody shed a light on this, please? Is this an American way of
rounding? Is there any European way of doing it in VB.NET?

Thorben
PS: The way VB.NET does this rounding is the way the manual describes it, I
just understand why things have changed, and why SQL-server does it
differently.
 
G

Guest

Hi

Use Math.Ceiling to always round up (and Math.Floor to round down)

Hope this helps, Synthanato

----- Test User wrote: ----

Hi all

I have learnt that if I want to round 0.5 to an integer the result should b
1, This is also the case if I do it in SQL server 2000, but if I do it i
VB.NET the result will be 0

Other rounding results: 1.5 = 2 in SQL and 2 in VB.NET which I believe i
corrrec
2.5 = 3 in SQL and 2 in VB.NET which I believe is wrong

Can anybody shed a light on this, please? Is this an American way o
rounding? Is there any European way of doing it in VB.NET

Thorbe
PS: The way VB.NET does this rounding is the way the manual describes it,
just understand why things have changed, and why SQL-server does i
differently
 
C

Cor

Hi Synthanator,

That is because Microsoft uses the ISO banking standard in dotNet, as far as
I know is the European way (or the way you showed in SQL) not available in
dotNet.

This question has been asked often here, but the only answers were as this
"why" and not "how".
(Except by not using the rounding and create your rounding math yourself)

http://msdn.microsoft.com/library/d...pref/html/frlrfsystemmathclassroundtopic3.asp

I am curious where this ISO banking standard is used as general rounding
system in the world.

Cor
 
A

Armin Zingler

Test User said:
Hi all,

I have learnt that if I want to round 0.5 to an integer the result
should be 1, This is also the case if I do it in SQL server 2000, but
if I do it in VB.NET the result will be 0.

Other rounding results: 1.5 = 2 in SQL and 2 in VB.NET which I
believe is corrrect
2.5 = 3 in SQL and 2 in VB.NET which I believe is wrong.

Can anybody shed a light on this, please? Is this an American way
of rounding? Is there any European way of doing it in VB.NET?

Thorben
PS: The way VB.NET does this rounding is the way the manual describes
it, I just understand why things have changed, and why SQL-server
does it differently.

It's call "mathematical" rounding (whoever needs this). It rounds to the
next even number.

You can use this function to get the "usual" rounding:

Public Function Round( _
ByVal value As Double, _
ByVal DecimalPlaces As Integer) _
As Double

Dim Faktor As Double = 10 ^ DecimalPlaces
Return Int(value * Faktor + 0.5) / Faktor

End Function


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
C

Cor

Hi,

That is because Microsoft uses the ISO banking standard in dotNet, as far as
I know is the European way (or the way you showed in SQL) not available in
dotNet.

This question has been asked often here, but the only answers were as this
"why" and not "how".
(Except by not using the rounding and create your rounding math yourself)

http://msdn.microsoft.com/library/d...pref/html/frlrfsystemmathclassroundtopic3.asp

I am curious where this ISO banking standard is used as general rounding
system in the world.

Cor
 

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

Top