Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

How do I round a variable that equals 5.125 or something at the 5 range to always round up - in this case to 5.13. Right now, I'm doing Round(x,2) with x = 5.125 and it still outputs 5.125.

Thanks.

Thanks.

That's odd. Try changing x to 5.1255 and see what happens.

From the c# help:

"When d is exactly halfway between two rounded values, the result is the rounded value that has an even digit in the far right decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. This process is known as rounding toward even, or rounding to nearest."

tqwu: Have something like this instead of round:

ceil(x*100)/100

Function TrueRound(number,places)

TrueRound = Ceil(number*(Math.pow(10,p

End Function

(If the above funciton is wrong, sorry, I'm not too good with ASP, but the concept remains, this is it in PHP:

function TrueRound($number,$places)

return(ceil($number*(pow(1

}

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

It took me too attempts to find a way around this. My first correction seemed to run straight into the original problem. However, this function seems to do the trick:

Function TrueRound(number, places)

TrueRound = Round(number, places)

If number * 10^places - TrueRound * 10^places = 0.5 Then TrueRound = TrueRound + 10^(-places)

End Function

Use TrueRound wherever you would otherwise be using Round, and I think you'll be okay.