473,715 Members | 4,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net 2003 rounding decimal value question

I am using vb.net 2003 professional and I get the following results
when using the round method:

dim Amount as decimal = 180.255
Amount = Amount.Round(Am ount, 2)

Amount now contains 180.25. I need it to contain 180.26.

Any ideas?
Nov 20 '05 #1
4 7830
Cor
Hi Spebola,
It is strange,
dim Amount as decimal = 180.255
Amount = Amount.Round(Am ount, 2) Amount now contains 180.25. I need it to contain 180.26.


I did try it and the result from me was 180.26, is there maybe a mouse on
your computer eating bits?

This is from MSDN
When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest.

Cor
Nov 20 '05 #2
sp*****@swbell. net (spebola) scripsit:
I am using vb.net 2003 professional and I get the following results
when using the round method:

dim Amount as decimal = 180.255
Amount = Amount.Round(Am ount, 2)

Amount now contains 180.25. I need it to contain 180.26.

Any ideas?


This code works for me (Windows XP Professional, .NET 1.1):

\\\
Dim Amount As Decimal = 180.255D
Amount = Amount.Round(Am ount, 2)
MsgBox(Amount.T oString())
///

Add 'Option Strict On' on top of your source file!

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Hi Spebola,

I can not reproduce the problem,
My test code and result is as follows.
Module Module1
Sub Main()
Dim Amount As Decimal = 180.255
Amount = Amount.Round(Am ount, 2)
Console.WriteLi ne(Amount)
End Sub
End Module
Output: 180.26

Did the problem persists with all number, such as , 180.177,180.173 ?
You may have a try to see if the problem is a common issue in your machine.
I will appricate the problem.
I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: sp*****@swbell. net (spebola)
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Subject: vb.net 2003 rounding decimal value question
Date: 10 Oct 2003 09:32:51 -0700
Organization : http://groups.google.com
Lines: 9
Message-ID: <b8************ **************@ posting.google. com>
NNTP-Posting-Host: 65.68.122.33
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google. com 1065803571 25204 127.0.0.1 (10 Oct 2003 16:32:51 GMT)X-Complaints-To: gr**********@go ogle.com
NNTP-Posting-Date: Fri, 10 Oct 2003 16:32:51 +0000 (UTC)
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.s yr.edu!news.max well.syr.edu!po stnews1.google. com!no
t-for-mailXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:145738
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I am using vb.net 2003 professional and I get the following results
when using the round method:

dim Amount as decimal = 180.255
Amount = Amount.Round(Am ount, 2)

Amount now contains 180.25. I need it to contain 180.26.

Any ideas?


Nov 20 '05 #4
Hi Spebola,

This behavior has been stated in the msdn.
Decimal.Round Method
When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position. For
example, when rounded to two decimals, the value 2.345 becomes 2.34 and the
value 2.355 becomes 2.36. This process is known as rounding toward even, or
rounding to nearest.
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemMath ClassAbsTopic.a sp

The behavior also exist in VB6.
189847 INFO: New String and Format Functions in Visual Basic 6.0
http://support.microsoft.com/?id=189847

You may refer to link below for more details about business rule.
http://www.uop.edu/cop/psychology/St.../Rounding.html
According to Hurlburt, 1994 pg. 12,the procedure for finding the last digit
of a
measure is called "Rounding".
Rule 3- To prevent rounding bias, if the remainder is exactly 5, then round
the
last digit to the closest even number.Thus the number 3.55 (rounded to 1
digit)
would be 3.6 (rounding up) and the number 6.450 would round to 6.4
(rounding
down)if rounding to 1 decimal.
See page 12 in Hurlburt, R. (1994) Comprehending Behavioral Statistics,
Brooks/Cole, Pacific Grove, CA.

This response contains a reference to a third-party World Wide Web site.
Microsoft is providing this information as a convenience to you. Microsoft
does not control these sites and has not tested any software or information
found on these sites; therefore, Microsoft cannot make any representations
regarding the quality, safety, or suitability of any software or
information found there. There are inherent dangers in the use of any
software found on the Internet, and Microsoft cautions you to make sure
that you completely understand the risk before retrieving any software from
the Internet.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: sp*****@swbell. net (spebola)
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Subject: vb.net 2003 rounding decimal value question
Date: 10 Oct 2003 09:32:51 -0700
Organization : http://groups.google.com
Lines: 9
Message-ID: <b8************ **************@ posting.google. com>
NNTP-Posting-Host: 65.68.122.33
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google. com 1065803571 25204 127.0.0.1 (10 Oct 2003 16:32:51 GMT)X-Complaints-To: gr**********@go ogle.com
NNTP-Posting-Date: Fri, 10 Oct 2003 16:32:51 +0000 (UTC)
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.s yr.edu!news.max well.syr.edu!po stnews1.google. com!no
t-for-mailXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:145738
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I am using vb.net 2003 professional and I get the following results
when using the round method:

dim Amount as decimal = 180.255
Amount = Amount.Round(Am ount, 2)

Amount now contains 180.25. I need it to contain 180.26.

Any ideas?


Nov 20 '05 #5

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

Similar topics

0
8821
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
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
9196
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...
0
7973
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...
1
6646
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
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
3175
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
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
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.