473,888 Members | 2,208 Online

# I want to correct Round function

Hi,
System.Math.Rou nd function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5
is round down)

Nov 21 '05 #1
17 5673
Nomenklatura,

I think you can trust the Round method to always act according to the
documentation:

"If value is halfway between two numbers, one of which is even and the other
odd, then the even number is returned."

"The behavior of this method follows IEEE Standard 754, section 4. This kind
of rounding is sometimes called rounding to nearest, or banker's rounding."

Kerry Moorman

"nomenklatu ra" wrote:
Hi,
System.Math.Rou nd function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5
is round down)

Nov 21 '05 #2
Kerry,
"If value is halfway between two numbers, one of which is even and the
other
odd, then the even number is returned."

"The behavior of this method follows IEEE Standard 754, section 4. This
kind
of rounding is sometimes called rounding to nearest, or banker's
rounding."

I am curious where this is used beside banking.

Is this standard used in your country and when yes, from what country are
you?

Cor
Nov 21 '05 #3
"nomenklatu ra" <il******@opera mail.com> wrote in message
news:eV******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
System.Math.Rou nd function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up, <5 is round down)

In this instance, add 0.005 and truncate. I would suggest writing your own
round function to handle various decimal places (e.g., MyRound, or
whatever).
Nov 21 '05 #4
"squig" <sq************ @midsouth.rr.co m> wrote in message
news:KN******** ***********@fe2 .columbus.rr.co m...
"nomenklatu ra" <il******@opera mail.com> wrote in message
news:eV******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
System.Math.Rou nd function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up,

<5
is round down)

In this instance, add 0.005 and truncate. I would suggest writing your own
round function to handle various decimal places (e.g., MyRound, or
whatever).

One caveat -- be careful using FormatNumber since it returns a character
string rather than numeric. If you have to do further computation with your
(rounded) number, you will need to convert it back to a numeric.
Nov 21 '05 #5
I am in Turkey.
We pass new Currency unit at new year.. (TL->YTL).
http://www.ytl.gen.tr/ytl/index_eng.php
The Ministry of Finance want to round this format..
That is not important odd or even..

And still i couldn't use round function..

"Cor Ligthert" <no************ @planet.nl>, iletide şunu yazdı
news:uu******** ******@TK2MSFTN GP10.phx.gbl...
Nov 21 '05 #6
nomenklatura,
It appears that VS.NET 2005 (aka Whidbey, due out later in 2005) adds
overloads to Math.Round to support current "banker's rounding" or the more
conventional "round up".

http://msdn2.microsoft.com/library/ef48waz8.aspx

Otherwise as squig suggests you probably want to create your own rounding
routine if "banker's rounding" is not appropriate for your routine...

Hope this helps
Jay

"nomenklatu ra" <il******@opera mail.com> wrote in message
news:eV******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
System.Math.Rou nd function is confused me.
for example i want to round 3.245 in with decimal symbol
Result should be = 3.25

When i try to this in vb:
A = 3.245
X = Round(A, 2)
then x=3.24 , result is is false

But when i try to A = 3.235
X = Round(A, 2)
then x=3.24 , result is true

So how can i trust this function.
Or are there any true round function which you know?
Not: Normally , I want to round with two decimal place (>=5 is round up,
<5
is round down)

Nov 21 '05 #7
i solved with FormatNumber functions
thanks all

Nov 21 '05 #8
"nomenklatu ra" <il******@opera mail.com> schrieb:
System.Math.Rou nd function is confused me.

In addition to the other replies:

How To Implement Custom Rounding Procedures
<URL:http://support.microso ft.com/?scid=kb;EN-US;196652>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #9
That is round-toward-even and I wish everyone would use it (it is more
accurate). Unfortunately, it is even harder than converting people to metric
systems. :(
Nov 21 '05 #10

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