Suppose there is a number 1.73. How to round it up to a larger number so that it becomes a multiple of 0.3? That is, to get, in this example, 1.8.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Divide the number by 0.3. Round up to a larger whole. Multiply by 0.3. Checking:

1,73 / 0,3 = 5,76 ceil(5,76) = 6 6 * 0.3 = 1.8 

You can perform integer division, and if the remainder is greater than 0, then add 0,3 - остаток to the original number. Checking on 0 is necessary not to round off, for example, 1.5 up to 1.8. Checking:

 1,73 % 0,3 = 0,23 0,23 != 0.0 0,3 - 0,23 = 0,07 1,73 + 0,07 = 1,8 
  • thanks for the help) - Kh.Bu