# Maximum PC

 It is currently Wed May 06, 2015 4:49 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Visual Basic 6 - How to round to 2 decimal placesPosted: Tue Aug 17, 2004 9:31 pm
 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

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

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

 Post subject: Standard rounding algorithmPosted: Wed Aug 18, 2004 11:08 am
 Team Member Top 100

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

 Post subject: Posted: Wed Aug 18, 2004 8:48 pm
 Little Foot

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets