In C#, how do I round a float upwards to the nearest int?
I see Math.Ceiling and Math.Round, but these returns a decimal. Do I use one of these then cast to an Int?
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.
If you want to round to the nearest int:
You can also use:
Which will use
Math.Round(x, 0);to round and cast for you. It looks neater but is slightly less clear IMO.If you want to round up: