if i have an integer a_variable = 1.1
how do i round it up to 2?
The basic function for rounding up is Math. Ceiling(d), but the asker specifically wanted to round up after the second decimal place. This would be Math. Ceiling(d * 100) / 100.
The Round method supports two rounding conventions for handling midpoint values: Rounding away from zero. Midpoint values are rounded to the next number away from zero. For example, 3.75 rounds to 3.8, 3.85 rounds to 3.9, -3.75 rounds to -3.8, and -3.85 rounds to -3.9.
In C#, Math. Round() is a Math class method which is used to round a value to the nearest integer or to the particular number of fractional digits. This method has another overload with which, you can specify the number of digits beyond the decimal point in the returned value.
50000001" will always round up and ". 4999999" will always round down the the nearest integer. So a 15.5 can never become a 14. Any value that is larger than 14.5 and smaller than 15.5 will round to 15 any value larger than 15.5 and smaller than 16.5 will round to 16.
Math.Ceiling(a_variable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With