473,473 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 8845
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
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.