Quantcast

Maximum PC

It is currently Wed Apr 23, 2014 6:00 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Visual Basic 6 - How to round to 2 decimal places
PostPosted: Tue Aug 17, 2004 9:31 pm 
Little Foot
Little Foot

Joined: Sun Jun 27, 2004 8:56 pm
Posts: 170
Does anyone know how to round a number (say 46.2153) to 46.22. I'm trying to make a program and I need the numbers I come up with to be accurate to 2 decimal places.


Top
  Profile  
 
 Post subject: Re: Visual Basic 6 - How to round to 2 decimal places
PostPosted: Wed Aug 18, 2004 9:55 am 
I'd rather be modding!
I'd rather be modding!
User avatar

Joined: Fri Jun 25, 2004 3:47 pm
Posts: 3731
Location: Las Vegas
fuzz_64 wrote:
Does anyone know how to round a number (say 46.2153) to 46.22. I'm trying to make a program and I need the numbers I come up with to be accurate to 2 decimal places.


"The Round() function is new in VB6. It rounds a number to the specified decimal places. So Round(11/3, 3) would round the result of 11 divided by 3 to three decimal places. The second argument is optional and defaults to zero. Round() is also hampered by odd numbers rounding up and even numbers rounding down at .5"

http://www.raritanval.edu/departments/c ... esson7.htm

Hope that helps
Manta


Top
  Profile  
 
 Post subject: Standard rounding algorithm
PostPosted: Wed Aug 18, 2004 11:08 am 
Team Member Top 100
Team Member Top 100
User avatar

Joined: Thu Jul 01, 2004 12:17 pm
Posts: 145
Location: Chicago area
The standard rounding algorithm goes something like this...

roundedNum = int( ( 100 * originalNum ) + 0.5 ) / 100

You would adjust the powers of 10 based on the number of decimal places you want (e.g., 10^2 for 2 decimal places; 10^3 for 3 decimal places, etc.).

If nothing else, it's a good chunk of code to keep in mind.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 8:48 pm 
Little Foot
Little Foot

Joined: Sun Jun 27, 2004 8:56 pm
Posts: 170
Worked great! Thank you very much!


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group