Skip to content

Commit 6ddfbe6

Browse files
authored
Add files via upload
1 parent 21aa9c4 commit 6ddfbe6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

maths/decimal_isolate.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Isolate the Decimal part of a Number
3+
"""
4+
5+
6+
def decimal_isolate(number, digitAmount):
7+
8+
"""
9+
Isolates the decimal part of a number.
10+
If digitAmount > 0 round to that decimal place, else print the entire decimal.
11+
>>> decimal_isolate(35.345, 1)
12+
0.3
13+
>>> decimal_isolate(35.345, 2)
14+
0.34
15+
>>> decimal_isolate(35.345, 3)
16+
0.345"""
17+
if digitAmount > 0:
18+
return round(number - int(number), digitAmount)
19+
return number - int(number)
20+
21+
22+
if __name__ == "__main__":
23+
print(decimal_isolate(35.345, 1))
24+
print(decimal_isolate(35.345, 2))
25+
print(decimal_isolate(35.345, 3))

0 commit comments

Comments
 (0)