I parsed a GET param named cb
,66.45, and I converted it into float,got 66.45.
cb = request.GET.get("cb", '')
if re.match('^\d+(\.\d+)?$', cb):
cb=float(cb)
params['cb'] = cb
And then I used it to query db data, got empty.
products = Product.objects.filter(**params)
In fact ,I found when debugging, the query sql used 66.4500000000000028421709430404007434844970703125
instead of 66.45
, and that caused my empty query result.
The cb
is defined in Product model as below:
cb = models.DecimalField(max_digits=6, decimal_places=2, default=0)
Is there anything wrong? I am confused.