mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-31 06:33:44 +00:00
07e991d553
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""
|
|
Isolate the Decimal part of a Number
|
|
https://stackoverflow.com/questions/3886402/how-to-get-numbers-after-decimal-point
|
|
"""
|
|
|
|
|
|
def decimal_isolate(number, digit_amount):
|
|
|
|
"""
|
|
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
|
|
>>> decimal_isolate(-14.789, 3)
|
|
-0.789
|
|
>>> decimal_isolate(0, 2)
|
|
0
|
|
>>> decimal_isolate(-14.123, 1)
|
|
-0.1
|
|
>>> decimal_isolate(-14.123, 2)
|
|
-0.12
|
|
>>> decimal_isolate(-14.123, 3)
|
|
-0.123
|
|
"""
|
|
if digit_amount > 0:
|
|
return round(number - int(number), digit_amount)
|
|
return number - int(number)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(decimal_isolate(1.53, 0))
|
|
print(decimal_isolate(35.345, 1))
|
|
print(decimal_isolate(35.345, 2))
|
|
print(decimal_isolate(35.345, 3))
|
|
print(decimal_isolate(-14.789, 3))
|
|
print(decimal_isolate(0, 2))
|
|
print(decimal_isolate(-14.123, 1))
|
|
print(decimal_isolate(-14.123, 2))
|
|
print(decimal_isolate(-14.123, 3))
|