473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Math.Round does not always show two decimal places

2 New Member
I'm writing a program in vb.net 2008 that calculates grades and puts them in a list. When I use Math.Round it will not show two decimal places for a number without decimals. For example:

This is what I have

100
96.97
93.94
...

Is there a way to force 100 or any other number that does not have decimals to have .00 after it?

Here is what I'm using in my code now

Str(Math.Round( i + HighGrade, 2, MidpointRoundin g.AwayFromZero) ).PadLeft(4)
Oct 5 '08 #1
2 5850
Curtis Rutland
3,256 Recognized Expert Specialist
Use String.Format. Check this page for how to use it. Scroll down a little bit.
Oct 5 '08 #2
Ricky71
2 New Member
Thank you so much!
It worked.

If anyone else has this problem, this is what I changed:

String.Format(" {0:#.00}", Math.Round(i + HighGrade, 2, MidpointRoundin g.AwayFromZero) ).PadLeft(4)

After String.Format use this "{0:#.00}" and replace the number of 0's after the decimal to what you need.
Oct 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

89
5112
by: Radioactive Man | last post by:
In python 2.3 (IDLE 1.0.3) running under windows 95, I get the following types of errors whenever I do simple arithmetic: 1st example: >>> 12.10 + 8.30 20.399999999999999 >>> 1.1 - 0.2 0.90000000000000013
40
2988
by: Chiwa | last post by:
Hey, Expression: Math.floor(x * 100) / 100 x= 4.1 gives 4.09, why in gods name? While other values for x don't give a problem. Thx in advance
5
2252
by: Ark | last post by:
Hi everyone, Does anyone know if Direct3D overloads System.Math functions? Also is it possible to access the base functions of the overloaded function (in other words restore original of the overlaoded function)? Thank you
6
9550
by: Mitchell Vincent | last post by:
Just making sure I'm not missing the boat here, but are there any special routines for doing currency math (fixed precision stuff) in .NET? The wonderful problems of doing math on decimals tend to shine when writing accounting software :-) How are others dealing with this? -- - Mitchell Vincent
4
3433
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal = 526.5 CType(Math.Round(ldecWater, 0), String) -- Chris Davoli
1
3529
by: William Stacey [MVP] | last post by:
int sqrft = 1335; decimal pricePerSqr = 18.33m; decimal pricePerYear = Math.Round(pricePerSqr * sqrft, 2, MidpointRounding.AwayFromZero); decimal pricePerMonth = Math.Round(pricePerYear / 12, 2, MidpointRounding.AwayFromZero); Console.WriteLine("/Sqr:"+pricePerSqr.ToString()); Console.WriteLine("/Year:"+pricePerYear.ToString()); Console.WriteLine("/Mth:"+pricePerMonth.ToString());
10
16019
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2) 0.74
2
5050
by: Radek Cerny | last post by:
Hopefully I'm just missing something obvious, but this method (or more likely the CLR/complier) has a bug where I can not use the overloaded version: Round( double value, int digits ) It always seems to use the Round(decimal value, int decimals) version, no matter what the first parameter is - double or decimal. Intellisense agrees with the compiler - incorrectly. Is it me, a known issue or a new issue? I need this quite...
4
10886
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
8674
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
9157
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...
1
8895
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
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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
4369
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.