Prev: External functions
Next: Drawing Curved Text
From: Valli on 27 Mar 2010 05:57 Hi, Dim d as double d= 0.5 Round(d) returns 0 d= 1.5 Round(d) returns 2 I need Round(0.5) = 1. Is it possible in .net? -- Thanks & regards, V.Vallikkannu This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and may be unlawful.
From: Armin Zingler on 27 Mar 2010 07:18 Am 27.03.2010 10:57, schrieb Valli: > Hi, > > Dim d as double > d= 0.5 > Round(d) returns 0 > > d= 1.5 > Round(d) returns 2 > > I need Round(0.5) = 1. Is it possible in .net? I don't know which Round function you are using here, without a qualifier. Try Math.Round: d = Math.Round(d, MidpointRounding.AwayFromZero) -- Armin
From: Michel Posseth [MCP] on 27 Mar 2010 08:37 For what it`s worth ,, The Round function goes to the nearest integer, and if there are two nearest integers then it goes to the even one. 1.5 rounds to 2, 0.5 rounds to 0. The behavior you noticed is not specific to .Net , it is called "Bankers rounding" and it is the standard rounding method used in every programming language dating back to COBOL and maybe even further ( maybe Cor can tell us that -) ) The rounding that you want is mathmetical rounding as how you have learned to round in basic scholar math courses this rounding method is midpointrounding away from zero http://blogs.msdn.com/ericlippert/archive/2003/09/26/bankers-rounding.aspx HTH Michel "Armin Zingler" <az.nospam(a)freenet.de> schreef in bericht news:%239U3l9ZzKHA.2016(a)TK2MSFTNGP02.phx.gbl... > Am 27.03.2010 10:57, schrieb Valli: >> Hi, >> >> Dim d as double >> d= 0.5 >> Round(d) returns 0 >> >> d= 1.5 >> Round(d) returns 2 >> >> I need Round(0.5) = 1. Is it possible in .net? > > I don't know which Round function you are using here, without a > qualifier. Try Math.Round: > > d = Math.Round(d, MidpointRounding.AwayFromZero) > > -- > Armin
From: Cor Ligthert[MVP] on 27 Mar 2010 16:57 Michel, Rounding was in the beginning not build in, you had to create your own mathematical functions for that. I was not aware before Net about Bankers rounding, can be lack of my knowledge but that is simply the truth Cor "Michel Posseth [MCP]" <msdn(a)posseth.com> wrote in message news:4D0D91AE-235C-47D6-80F3-19B3788DE43B(a)microsoft.com... > > For what it`s worth ,, > > The Round function goes to the nearest integer, and if there are two > nearest integers then it goes to the even one. 1.5 rounds to 2, 0.5 > rounds to 0. > > The behavior you noticed is not specific to .Net , it is called "Bankers > rounding" and it is the standard rounding method used in every programming > language > dating back to COBOL and maybe even further ( maybe Cor can tell us > that -) ) > > The rounding that you want is mathmetical rounding as how you have learned > to round in basic scholar math courses > this rounding method is midpointrounding away from zero > > http://blogs.msdn.com/ericlippert/archive/2003/09/26/bankers-rounding.aspx > > > HTH > > Michel > > > "Armin Zingler" <az.nospam(a)freenet.de> schreef in bericht > news:%239U3l9ZzKHA.2016(a)TK2MSFTNGP02.phx.gbl... >> Am 27.03.2010 10:57, schrieb Valli: >>> Hi, >>> >>> Dim d as double >>> d= 0.5 >>> Round(d) returns 0 >>> >>> d= 1.5 >>> Round(d) returns 2 >>> >>> I need Round(0.5) = 1. Is it possible in .net? >> >> I don't know which Round function you are using here, without a >> qualifier. Try Math.Round: >> >> d = Math.Round(d, MidpointRounding.AwayFromZero) >> >> -- >> Armin >
From: Tom Shelton on 28 Mar 2010 03:13
On 2010-03-27, Cor Ligthert[MVP] <Notmyfirstname(a)planet.nl> wrote: > Michel, > > Rounding was in the beginning not build in, you had to create your own > mathematical functions for that. > > I was not aware before Net about Bankers rounding, can be lack of my > knowledge but that is simply the truth > VB has used bankers rounding by default for as long as I can remember. -- Tom Shelton |