Skip to content

Instantly share code, notes, and snippets.

@vafrcor
Created December 3, 2020 00:34
Show Gist options
  • Save vafrcor/58d3c2a457b944998ef3bbb828a2464f to your computer and use it in GitHub Desktop.
Save vafrcor/58d3c2a457b944998ef3bbb828a2464f to your computer and use it in GitHub Desktop.
Rounding by Multiply Factor in python
def round_multiply_by_factor(factor: float = 0, input_value: float = 0 ) -> float:
fix = False
x= input_value
y= 1.0
while fix == False:
if x <= (y * factor):
x= y * factor
fix = True
y+=1
return x
# Weight Round Multiply Factor
print('\nWeight Round Multiply Factor \n-----------------------------------------\n')
print('{} >> {}'.format(1.0, round_multiply_by_factor(100, 1.0)))
print('{} >> {}'.format(50.0, round_multiply_by_factor(100, 50.0)))
print('{} >> {}'.format(100.0, round_multiply_by_factor(100, 100.0)))
print('{} >> {}'.format(101.0, round_multiply_by_factor(100, 101.0)))
# Volume Round Multiply Factor
print('\nVolume Round Multiply Factor \n-----------------------------------------\n')
print('{} >> {}'.format(0.5, round_multiply_by_factor(1, 0.5)))
print('{} >> {}'.format(1.0, round_multiply_by_factor(1, 1.0)))
print('{} >> {}'.format(1.5, round_multiply_by_factor(1, 1.5)))
print('{} >> {}'.format(2.0, round_multiply_by_factor(1, 2.0)))
print('{} >> {}'.format(2.1, round_multiply_by_factor(1, 2.1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment