Is there a way to round the number 15.50193475 to 15.50 instead of 15.5?
Printable View
Is there a way to round the number 15.50193475 to 15.50 instead of 15.5?
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.
what will that do if i have a number that actually works like 15.645
It'll just turn it into 15.64. You want it to round to 15.65?
Ancient chinese secretQuote:
Originally posted by Azkar
what will that do if i have a number that actually works like 15.645
Oh okay, i just want it to use a 0 for a place holder if its not 2 places after the decimal
After looking in the MSDN I found that this should work to round.
That should return 15.50VB Code:
Round(15.50193475, 2)
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.
If you're rounding to 2 decimal places, it will probably will only use those 2, so it just discards the 5Quote:
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.
Maybe this thread helps, about rounding toward even.