How would you round up a decimal or float to an integer. For instance...
0.0 => 0 0.1 => 1 1.1 => 2 1.7 => 2 2.1 => 3
Etc.
Reference (thanks Rawling) Explicit Numeric Conversions Table: When you convert a double or float value to an integral type, this value is rounded towards zero to the nearest integral value.
Rounding to the Nearest IntegerIf the digit in the tenths place is less than 5, then round down, which means the units digit remains the same; if the digit in the tenths place is 5 or greater, then round up, which means you should increase the unit digit by one.
Round() . If using MidpointRounding. ToEven (the default) the value is rounded to the nearest even number ( 1.5 is rounded to 2 , but 2.5 is also rounded to 2 ).
Simple, use Math.Ceiling
:
var wholeNumber = (int)Math.Ceiling(fractionalNumber);
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