Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add python validators for decimal constraints (max_digits anddecimal_places)#10506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 13 commits intomainfromadd-decimal-validators
Sep 27, 2024
Merged
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
a few inline examples
  • Loading branch information
@sydney-runkle
sydney-runkle committedSep 27, 2024
commit75ba3dbbe160cbd055ba33878c52f18e8b350c19
12 changes: 7 additions & 5 deletionspydantic/_internal/_validators.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -361,14 +361,16 @@ def _extract_decimal_digits_info(decimal: Decimal, normalized: bool) -> tuple[in

if exponent >= 0:
# A positive exponent adds that many trailing zeros
# Ex: digit_tuple=(1, 2, 3), exponent=2 -> 12300 -> 0 decimal places, 5 digits
digits += exponent
decimal_places = 0
else:
# If the absolute value of the negative exponent is larger than the
# number of digits, then it's the same as the number of digits,
# because it'll consume all the digits in digit_tuple and then
# add abs(exponent) - len(digit_tuple) leading zeros after the
# decimal point.
# If the absolute value of the negative exponent is larger than the
# number of digits, then it's the same as the number of digits,
# because it'll consume all the digits in digit_tuple and then
# add abs(exponent) - len(digit_tuple) leading zeros after the decimal point.
# Ex: digit_tuple=(1, 2, 3), exponent=-2 -> 1.23 -> 2 decimal places, 3 digits
# Ex: digit_tuple=(1, 2, 3), exponent=-4 -> 0.0123 -> 4 decimal places, 4 digits
decimal_places = abs(exponent)
digits = max(digits, decimal_places)

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp