Suppose there is a number

3686,55 

I want to drop the fractional part - you can handle this with

 Convert.ToInt32(); 

Now the number 3686 remains. It is necessary to round it depending on the value of the last digit - if it is within 01234 - then round it down, and if 56789 , then it will 01234 big. In my case it should be 3690.

I found methods for fractional numbers - but for integers I could not find it. Tell me how to be

  • one
    I found methods for fractional numbers - but for integers I could not find it. Dozens divided into the necessary degree, rounded the resulting “fractional”, then the multiplication back. - Akina

1 answer 1

Divide by 10, round off as real, lead to a whole, then multiply back by 10:

 double d = 3686.55; int i = (int) Math.Round(d / 10) * 10; Console.WriteLine( i ); 
 3690