MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / decimal_isolate

Function decimal_isolate

maths/decimal_isolate.py:7–32  ·  view source on GitHub ↗

Isolates the decimal part of a number. If digitAmount > 0 round to that decimal place, else print the entire decimal. >>> decimal_isolate(1.53, 0) 0.53 >>> decimal_isolate(35.345, 1) 0.3 >>> decimal_isolate(35.345, 2) 0.34 >>> decimal_isolate(35.345, 3) 0.345

(number: float, digit_amount: int)

Source from the content-addressed store, hash-verified

5
6
7def decimal_isolate(number: float, digit_amount: int) -> float:
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(1.53, 0)
12 0.53
13 >>> decimal_isolate(35.345, 1)
14 0.3
15 >>> decimal_isolate(35.345, 2)
16 0.34
17 >>> decimal_isolate(35.345, 3)
18 0.345
19 >>> decimal_isolate(-14.789, 3)
20 -0.789
21 >>> decimal_isolate(0, 2)
22 0
23 >>> decimal_isolate(-14.123, 1)
24 -0.1
25 >>> decimal_isolate(-14.123, 2)
26 -0.12
27 >>> decimal_isolate(-14.123, 3)
28 -0.123
29 """
30 if digit_amount > 0:
31 return round(number - int(number), digit_amount)
32 return number - int(number)
33
34
35if __name__ == "__main__":

Callers 1

decimal_isolate.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected