Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round a value to nearest number divisible by 2, 4, 8 and 16?

Tags:

python

How do i round a decimal number to the nearest number divisible by 2, 4, 8 and 16 in python?

Example:

1920/1.33 = 1443.609022556391 

It should round off to 1440 as it is easily divisible by the 2, 4, 8 and 16 and vice versa ( 1440*1.33 = 1920 ).

1920/1.33 = 1440
like image 318
Vivek Singh Avatar asked Aug 27 '14 14:08

Vivek Singh


People also ask

How find numbers that are divisible by another number?

A number is divisible by another number if it can be divided equally by that number; that is, if it yields a whole number when divided by that number. For example, 6 is divisible by 3 (we say "3 divides 6") because 6/3 = 2, and 2 is a whole number.

How do you round to 5 in Python?

Round a Number Down to the nearest 5 in Python #Call the math. floor() method passing it the number divided by 5 . Multiply the result by 5 . The result of the calculation is the number rounded down to the nearest 5 .

How do you round a value in Python?

Python has a built-in round() function that takes two numeric arguments, n and ndigits , and returns the number n rounded to ndigits . The ndigits argument defaults to zero, so leaving it out results in a number rounded to an integer.

How do you make a number divisible by 5?

The divisibility rule of 5 states that if the digit on the units place, that is, the last digit of a given number is 5 or 0, then such a number is divisible by 5. For example, in 39865, the last digit is 5, hence, the number is completely divisible by 5.


1 Answers

What about int( 16 * round( value / 16. )) ?

like image 80
Mathias Dolidon Avatar answered Sep 23 '22 03:09

Mathias Dolidon