- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathround.py
More file actions
Latest commit
40 lines (31 loc) · 1.03 KB
/
Copy pathround.py
File metadata and controls
40 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Programa desarrollado por el Licenciado César Cordero Rodríguez.
Bajo licencia GPLv3.
Puede ser modificado, copiado y distribuido.
Se desarrolló con fines educativos.
"""
#
# It does the function of
# MULTIPLO.SUPERIOR.XCL in Excel in Microsoft Office
# and Calc in LibreOffice
#
# Running example:
# python round.py 5.9 0.9 2
# Result: Rounded 6.3
#
# python round.py 5.9 0.3442 4
# Result: Rounded 6.1956
#
importsys
def_get_multiple_up_rounded(number, rounded, number_of_decimals):
result_mod=round(float(number%rounded), int(number_of_decimals))
ifresult_mod!=0:
result=round(float((number-result_mod) +rounded), int(number_of_decimals))
else:
result=round(float(number), int(number_of_decimals))
returnresult
number_of_decimals=sys.argv[3]
number=round(float(sys.argv[1]), int(number_of_decimals))
rounded=float(sys.argv[2])
print("Rounded "+str(_get_multiple_up_rounded(number, rounded, number_of_decimals)))