Skip to content

Commit bd41bc3

Browse files
authored
Update helper.py
1 parent f129582 commit bd41bc3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

deepdiff/helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ def number_to_string(number: Any, significant_digits: int, number_format_notatio
434434
# For example '999.99999999' will become '1000.000000' after quantize
435435
ctx.prec += 1
436436
number = number.quantize(Decimal('0.' + '0' * significant_digits))
437+
elif isinstance(number, Fraction):
438+
# Convert Fraction to float so that string formatting works on Python < 3.12
439+
number = round(float(number), significant_digits)
440+
if significant_digits == 0:
441+
number = int(number)
437442
elif isinstance(number, only_complex_number): # type: ignore
438443
# Case for complex numbers.
439444
number = number.__class__(

0 commit comments

Comments
 (0)