我想在Place模型中保存纬度和经度.
我尝试了两个字段,floatfield和decimalfield.
1. FloatField模型
class Place1(models.Model):
latitude = models.FloatField()
longitude = models.FloatField()
2. DecimalField模型
class Place2(models.Model):
latitude = models.DecimalField(max_digits=18, decimal_places=16)
longitude = models.DecimalField(max_digits=19, decimal_places=16)
两个字段都适用于以下值.
10.1
10.12
10.123
10.1234
…
10.1234567890123
但是,在第16个数字(不是“十六个小数位”)之后,保存时会无意中舍入.
place1 = Place1.objects.create(
latitude=10.123456789012345,
longitude=100.123456789012345
)
>>place1.latitude
10.123456789012345 # works well
>>place1.longitude
100.123456789012345 # works well
# Unintentionally rounded when I get object from