|
-
Sep 5th, 2009, 04:39 PM
#1
Thread Starter
Hyperactive Member
Need help with rounding numbers.
I understand the concept of rounding I guess, all I know is math.round(), but I need a break down of it so I can round a number like this: 14.789543 to this: 14.8 because after the 7 there is an 8, which means you would round the seven up. Can anyone tell me how this is done?
And some more detail, I need to round to the nearest tenth.
-
Sep 5th, 2009, 04:52 PM
#2
New Member
Re: Need help with rounding numbers.
There is second optional parameter that can be sent to this function that returns it to a decimal point. So...
math.round(14.789543, 1) would return 14.8.
-
Sep 5th, 2009, 05:09 PM
#3
Thread Starter
Hyperactive Member
Re: Need help with rounding numbers.
 Originally Posted by sra3cf
There is second optional parameter that can be sent to this function that returns it to a decimal point. So...
math.round(14.789543, 1) would return 14.8.
Thaty works somewhat, the only problem is that It's not rounding the decimal, it's rounding to the nearest whole digit.
I need it to round to the nearest tenth.
-
Sep 5th, 2009, 05:16 PM
#4
Re: Need help with rounding numbers.
Well are you storing the result as an Integer? Integers cannot hold Decimal places.
This is wrong:
vb.net Code:
Dim x As Integer = Math.Round(14.7859, 1) 'This will remove the decimal!!!
This is more logical:
vb.net Code:
Dim x As Double = Math.Round(14.7859, 1) 'This will not!
Doubles are designed to perform math operations, and the Math.Round() Function returns a double.
-
Sep 5th, 2009, 05:29 PM
#5
Re: Need help with rounding numbers.
Decimal will work better than Double too...
-tg
-
Sep 5th, 2009, 05:30 PM
#6
Thread Starter
Hyperactive Member
Re: Need help with rounding numbers.
Alright, I figured out my problem, my problem was that I was rounding a number from a textbox, so I was using CInt when I should have been using CDbl. Now can anyone tell me how to round to the nearest hundredth?
-
Sep 5th, 2009, 05:34 PM
#7
Re: Need help with rounding numbers.
Someone already did, have you tried changing 2nd parameter of math.round at all?
-
Sep 5th, 2009, 07:19 PM
#8
Re: Need help with rounding numbers.
 Originally Posted by techgnome
Decimal will work better than Double too...
-tg
Forgot about Decimal. I just usually use Double because I've never had a need to use it yet..
-
Sep 5th, 2009, 08:35 PM
#9
Thread Starter
Hyperactive Member
Re: Need help with rounding numbers.
Before I can mark this resolved, how could I round to say, the nearest 10, like if the number is 56, it will round up to 60.
-
Sep 6th, 2009, 12:36 AM
#10
Re: Need help with rounding numbers.
divide by 10, round, multiply by 10
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|