Created
December 14, 2021 05:35
-
-
Save gyli/b9691139999c15b0cf9f7dfabedf0cd6 to your computer and use it in GitHub Desktop.
Calculate range of Decimal with precision and scale
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
from typing import Decimal, Tuple | |
def calculate_decimal_range(precision: int, scale: int) -> Tuple[Decimal, Decimal]: | |
""" | |
This method calculates the range of Decimal with given precision and scale. | |
:return: (min_value, max_value) | |
""" | |
precision, scale = Decimal(precision), Decimal(scale) | |
max_value = 10**(precision-scale) - 10**-scale | |
return -max_value, max_value | |
# Input: | |
# precision=10 | |
# scale=5 | |
# Output: | |
# (Decimal('-99999.99999'), Decimal('99999.99999')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment