Created
December 3, 2020 00:34
-
-
Save vafrcor/58d3c2a457b944998ef3bbb828a2464f to your computer and use it in GitHub Desktop.
Rounding by Multiply Factor in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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