How can I round values to nearest integer?
For example:
1.1 => 1
1.5 => 2
1.9 => 2
“Math.Ceiling()” is not helping me. Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See the official documentation for more. For example:
Basically you give the
Math.Roundmethod three parameters.Sample code:
Live Demo
You need
MidpointRounding.AwayFromZeroif you want a .5 value to be rounded up. Unfortunately this isn’t the default behavior forMath.Round(). If usingMidpointRounding.ToEven(the default) the value is rounded to the nearest even number (1.5is rounded to2, but2.5is also rounded to2).