|
-
Aug 23rd, 2003, 08:59 PM
#1
Thread Starter
Lively Member
rounding with deciamals...
Is there a way to round the number 15.50193475 to 15.50 instead of 15.5?
-
Aug 23rd, 2003, 09:12 PM
#2
Addicted Member
Yes. Here's a code snippet from a project I did in school.
VB Code:
pdblAverage = ToDouble(pdblGrade1 + pdblGrade2 + pdblGrade3) / 3
psngAverage = System.Convert.ToSingle(pdblAverage)
lblAverage.Text = psngAverage.ToString("##.00")
its the ("##.00") at the end that dtermines how many decimals to extend the number to.
Take my love
Take my land
Take me where I cannot stand
I don't care, I'm still free
You can't take the sky from me...
-
Aug 23rd, 2003, 09:19 PM
#3
Thread Starter
Lively Member
what will that do if i have a number that actually works like 15.645
-
Aug 23rd, 2003, 09:21 PM
#4
Addicted Member
It'll just turn it into 15.64. You want it to round to 15.65?
Take my love
Take my land
Take me where I cannot stand
I don't care, I'm still free
You can't take the sky from me...
-
Aug 23rd, 2003, 09:24 PM
#5
Originally posted by Azkar
what will that do if i have a number that actually works like 15.645
Ancient chinese secret
-
Aug 23rd, 2003, 09:31 PM
#6
Thread Starter
Lively Member
Oh okay, i just want it to use a 0 for a place holder if its not 2 places after the decimal
-
Aug 23rd, 2003, 09:35 PM
#7
Addicted Member
After looking in the MSDN I found that this should work to round.
That should return 15.50
If you use a variable:
VB Code:
dim MyNumber as double = 15.50193475
Round(MyNumber, 2)
I cant seem to find anything about actual rounding though. They always round to even. Like if its 16.345, it become 16.34 instead of 16.35.
<EDIT>
Right, the zeros are just placeholders.
Take my love
Take my land
Take me where I cannot stand
I don't care, I'm still free
You can't take the sky from me...
-
Aug 23rd, 2003, 10:06 PM
#8
Originally posted by The Phoenix
I cant seem to find anything about actual rounding though. They always round to even. Like if its 16.345, it become 16.34 instead of 16.35.
If you're rounding to 2 decimal places, it will probably will only use those 2, so it just discards the 5
-
Aug 24th, 2003, 12:28 AM
#9
Frenzied Member
Maybe this thread helps, about rounding toward even.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
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
|