473,888 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Similar topics

3
23518
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. Math.Round(3.46, 1); //Returns 3.5. but what I am looking for is a round function that returns 3.5 when rounding the value 3.45 in the above. By the way The ToString does a normal rounding - thank you Microsoft!
9
7391
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 different. Programming Microsoft Windows with Microsoft Visual Basic.NET "The Round method with a single argument return the whole number nearest to the argument. If the argument to Round is midway between two whole numbers,
5
4256
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))
2
1314
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
9
6568
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 function round() as seen below: 0 2 2
0
1017
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 to see the exact representation of this value on your system, it may be just over or just down by a small quantity. On mine with 2.6 this typically give : ...: 0.5
1
3073
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. I haven't much experience in using the Timer class or the Math class. I may be overlooking something stupid and the solution is probably really simple (happens a lot to me).. here's the piece of code.. //Retrieve time and round it off. ...
0
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10772
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10878
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5810
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4635
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4239
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.