There is a number 1.08 . How to make it rounded to 2? Those. if the number is greater than 1, even by the thousand, then increase to 2.

    1 answer 1

    Rounding to the nearest larger integer:

     double d = Math.Ceiling(1.08); // => 2 

    Rounding to the nearest smaller integer:

     double d = Math.Floor(1.08); // => 1 

    Fractional drop:

     double d = Math.Truncate(1.08); // => 1 

    It may seem that Floor and Truncate identical, but this is not the case for negative numbers:

     double d = Math.Floor(-1.08); // => -2 

    whereas

     double d = Math.Truncate(-1.08); // => -1 
    • More about Trunc should be added then. - Kromster