﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34363	"floatformat() crashes on ""0.0000"""	Takis Issaris	Takis Issaris	"Similar to #34272 the current Django code (both 4.2b1 and latest git) crash on using the `floatformat` template filter with
0 values.

{{{#!python
from decimal import Decimal
from django.template.defaultfilters import floatformat

floatformat('0.0000', 2)
floatformat(Decimal('0.0000'), 2)
}}}
Both throw {{{ValueError: valid range for prec is [1, MAX_PREC]}}}

Using `git bisect` I tracked the bug to commit 08c5a787262c1ae57f6517d4574b54a5fcaad124.

When one uses `""0.0000"": floatformat:2` the current code results in a precision of 0 which is
not allowed:

{{{
tupl = d.as_tuple()                   # with d being ""0.0000"" returns (sign=0,digits=(0,),exponent=-4)
units = len(tupl[1])                  # equals 1
units += -tupl[2] if m else tupl[2]   # 1 + (-4)
prec = abs(p) + units + 1             # 2 (number of requested decimals) + (-3) + 1 equals 0

rounded_d = d.quantize(exp, ROUND_HALF_UP, Context(prec=prec))
}}} 
"	Bug	closed	Template system	4.2	Release blocker	fixed	filters	David Wobrock	Ready for checkin	1	0	0	0	0	0
