473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

math.round problem

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.


Nov 20 '05 #1
12 8842
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

Nov 20 '05 #2
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

Nov 20 '05 #3
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/de...oundtopic3.asp

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

Cor
Nov 20 '05 #4
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/de...oundtopic3.asp

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

Cor
Nov 20 '05 #5
"Test User" <Te**@test.dk> schrieb
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
Nov 20 '05 #6
"Test User" <Te**@test.dk> schrieb
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
Nov 20 '05 #7
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/de...oundtopic3.asp

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

Cor

Nov 20 '05 #8
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/de...oundtopic3.asp

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

Cor

Nov 20 '05 #9
Cor
Hi Synthanator,

Sorry the message was not to you I corrected that,

Cor
Nov 20 '05 #10
Cor
Hi Synthanator,

Sorry the message was not to you I corrected that,

Cor
Nov 20 '05 #11
Hi Cor, no problems :)
Nov 20 '05 #12
Hi Cor, no problems :)
Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ng_mr | last post by:
No, not a question about "banker's rounding" or whatever it's called. I want to round a double to the nearest 100th, so I perform the following: // original is a double double result =...
6
by: Test User | last post by:
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. ...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
3
by: Altman | last post by:
OK I was having rounding problems before and I didn't realize that their was a third parameter in the round function that would tell it if it a 5 to round up. I thought adding this would fix the...
6
by: Zeng | last post by:
Math.Round has good behavior as following: Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is even Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.