Search code examples
c#doublepointdigitsceil

Ceiling double two digits after point


I have two numbers, for example:

1.51 and 1.56

I need to have:

1.55 and 1.60

but, if it is 1.55 it just stay as 1.55.


Solution

  • public double MyCeiling(double value)
    {
        return Math.Ceiling(value * 20) / 20;
    }
    

    Usage:

    double d1 = MyCeiling(1.51); // result 1.55
    double d2 = MyCeiling(1.55); // result 1.55
    double d3 = MyCeiling(1.56); // result 1.6