How to round a number down to the nearest 10 in C#

1 Answer

0 votes
using System;

class Program
{
    static double roundDownToNearest10(double num) {
        return Math.Floor(num / 10) * 10;
    }
    static void Main() {
        Console.WriteLine(roundDownToNearest10(33));
        Console.WriteLine(roundDownToNearest10(59));
        Console.WriteLine(roundDownToNearest10(599.99));
        Console.WriteLine(roundDownToNearest10(3.14));
        Console.WriteLine(roundDownToNearest10(2));
        Console.WriteLine(roundDownToNearest10(19));
        Console.WriteLine(roundDownToNearest10(-12));
        Console.WriteLine(roundDownToNearest10(-101));
        Console.WriteLine(roundDownToNearest10(-109));
    }
}




/*
run:
 
30
50
590
0
0
10
-20
-110
-110
 
*/

 



answered Jun 9, 2022 by avibootz

Related questions

1 answer 123 views
1 answer 126 views
1 answer 110 views
1 answer 120 views
1 answer 123 views
1 answer 105 views
...