Django: allow a FloatField or an IntegerField in an input form? -
i have django model field price:
class book(models.model): title = models.charfield(max_length=200) price = models.floatfield(null=true, blank=true)
the issue users might enter price 245 or 245.00, , want system able handle either.
can clever allow this?
i don't understand why need @ all. float doesn't have have floating-point component - 245
valid float 245.00
.
i second maikhoepfel's recommendation don't use floats prices, though. floating point isn't able represent decimal values - limitation of standard ieee floating-point algorithm. however, i'd recommend use decimalfield
instead, ideal values fixed number of decimal places, prices.
Comments
Post a Comment