Hi,
System.Math.Round 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) 17 5619
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
"nomenklatura" wrote: Hi, System.Math.Round 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)
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
"nomenklatura" <il******@operamail.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl... Hi, System.Math.Round 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).
"squig" <sq************@midsouth.rr.com> wrote in message
news:KN*******************@fe2.columbus.rr.com... "nomenklatura" <il******@operamail.com> wrote in message news:eV**************@TK2MSFTNGP10.phx.gbl... Hi, System.Math.Round 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.
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**************@TK2MSFTNGP10.phx.gbl...
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
"nomenklatura" <il******@operamail.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl... Hi, System.Math.Round 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)
i solved with FormatNumber functions
thanks all
"nomenklatura" <il******@operamail.com> schrieb: System.Math.Round function is confused me.
In addition to the other replies:
How To Implement Custom Rounding Procedures
<URL:http://support.microsoft.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/>
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. :(
"Randy Given" <Gi********@aol.com> wrote in message
news:73swd.6024$sf5.840@lakeread05... 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. :(
Not trying to be argumentative but please explain how it is more accurate --
maybe I'm not fully understanding your comment.
Squig,
Why you do else think they call it "banking" system.
The way that is always been used is alway for 4 figurs down(1,2,3,4) and for
5 up(5,6,7,8,9)
That is eliminated in this system too an equal situations where it is 4,5
times down and 4,5 times up.
However as Randy said it is hardly used.
Probably because you need a computer to use it.
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OU**************@TK2MSFTNGP14.phx.gbl... Squig,
Why you do else think they call it "banking" system.
The way that is always been used is alway for 4 figurs down(1,2,3,4) and
for 5 up(5,6,7,8,9)
That is eliminated in this system too an equal situations where it is 4,5 times down and 4,5 times up.
However as Randy said it is hardly used.
Probably because you need a computer to use it.
Cor
Okay, but it still doesn't explain how it is more accurate. I understand the
concept.
Squig, Okay, but it still doesn't explain how it is more accurate. I understand the concept.
A rounding is never accurate. However, in this newsgroup with so many
persons whose native language is not English, it is used that you try to
understand, not to pick on words.
Just my thought,
Cor
Squig,
The way I understand it is:
Rather then always rounding the mid point up, "half of the time" you are
rounding it up & "half of the time" you are rounding it down.
The two "half of the time" together will average themselves out of the
picture.
When you always rounding the mid point up, then you start accumulating all
the fractions, rather then average them out...
The following demonstrates this:
Public Shared Sub Main()
Dim value1 As Decimal = 1.235D
Dim value2 As Decimal = 1.245D
Dim value3 As Decimal = value1 + value2
Dim value4 As Decimal = Decimal.Round(value1, 2) +
Decimal.Round(value2, 2)
Dim value5 As Decimal = RoundUp(value1, 2) + RoundUp(value2, 2)
Debug.WriteLine(value1, "value1")
Debug.WriteLine(value2, "value2")
Debug.WriteLine(value3, "value3")
Debug.WriteLine(value4, "value4")
Debug.WriteLine(value5, "value5")
End Sub
' may not handle negative value correctly...
Private Shared Function RoundUp(ByVal value As Decimal, ByVal decimals
As Integer) As Decimal
decimals = CInt(10 ^ decimals)
value *= decimals
value = Decimal.Truncate(value + 0.5D)
value /= decimals
Return value
End Function
Notice how value4 & value5 are off by 1, if you are lot of rounding, this
can add up significantly. When you use banking rounding, this difference
will not add up as quickly or as much...
Hope this helps
Jay
"squig" <sq************@midsouth.rr.com> wrote in message
news:X9****************@fe1.columbus.rr.com... "Randy Given" <Gi********@aol.com> wrote in message news:73swd.6024$sf5.840@lakeread05... 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. :(
Not trying to be argumentative but please explain how it is more accurate -- maybe I'm not fully understanding your comment.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:#R**************@TK2MSFTNGP11.phx.gbl... Squig, Okay, but it still doesn't explain how it is more accurate. I understand the concept.
A rounding is never accurate. However, in this newsgroup with so many persons whose native language is not English, it is used that you try to understand, not to pick on words.
Just my thought,
Cor
Wasn't picking on words -- I'm trying to understand the reasoning behind it
being more accurate.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl... Squig, The way I understand it is:
Rather then always rounding the mid point up, "half of the time" you are rounding it up & "half of the time" you are rounding it down.
The two "half of the time" together will average themselves out of the picture.
When you always rounding the mid point up, then you start accumulating all the fractions, rather then average them out...
The following demonstrates this:
Public Shared Sub Main() Dim value1 As Decimal = 1.235D Dim value2 As Decimal = 1.245D
Dim value3 As Decimal = value1 + value2
Dim value4 As Decimal = Decimal.Round(value1, 2) + Decimal.Round(value2, 2) Dim value5 As Decimal = RoundUp(value1, 2) + RoundUp(value2, 2)
Debug.WriteLine(value1, "value1") Debug.WriteLine(value2, "value2") Debug.WriteLine(value3, "value3") Debug.WriteLine(value4, "value4") Debug.WriteLine(value5, "value5") End Sub
' may not handle negative value correctly... Private Shared Function RoundUp(ByVal value As Decimal, ByVal decimals As Integer) As Decimal decimals = CInt(10 ^ decimals) value *= decimals value = Decimal.Truncate(value + 0.5D) value /= decimals Return value End Function
Notice how value4 & value5 are off by 1, if you are lot of rounding, this can add up significantly. When you use banking rounding, this difference will not add up as quickly or as much...
Hope this helps Jay
Thanks for the explanation. The last sentence sums up why, which is what I
was asking.
> Not trying to be argumentative but please explain how it is more accurate -- maybe I'm not fully understanding your comment.
If you have these numbers:
1.5
2.5
3.5
4.5
The real total is 12.
Rounding up (typical way) gives 14:
1.5 -> 2
2.5 -> 3
3.5 -> 4
4.5 -> 5
Rounding toward even gives 12:
1.5 -> 2
2.5 -> 2
3.5 -> 4
4.5 -> 5
See? More accurate on average. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ORC |
last post by:
Is there a round function that do a "Normal" rounding and not the round to
nearest as the Math.Rounds is?
Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4....
|
by: Ronald W. Roberts |
last post by:
I'm having a problem understanding the Round function. Below are quotes
from two
books on VB.NET. The first book shows examples with one argument and
how it
rounds. The second book something...
|
by: Marc |
last post by:
Hi,
I cannot get the round function to work on vb.net. I get the message
that round is not declared?
Has round function changed or something?
MsgBox(round(3, 3))
|
by: shashiramu |
last post by:
Hi there,
Am trying to round a value 36.825 to 36.82,
But if i use ROUND function it is giving me 36.83
so can anyone help me in getting the value i needed
Thanks in Advance
Shashi
|
by: josh logan |
last post by:
Hello,
I need a round function that _always_ rounds to the higher integer if
the argument is equidistant between two integers. In Python 3.0, this
is not the advertised behavior of the built-in...
|
by: Maric Michaud |
last post by:
Le Monday 28 July 2008 02:35:08 Herman, vous avez écrit :
Hmm, I don't have the same result in python2.6, I suspect it's a floating
point precision problem, try just to type "0.5" in the console...
|
by: RiK ooo |
last post by:
Hi, i'm currently working on C# project and I want to make use of the Math.Round() function to display only the first to digits of a float value. Unfortunately this doesn't seem to be working for me....
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |