What's the best开发者_开发问答 type to store values such:
48.89384
and -2.34910
Actually I'm using float
.
Use decimal for exact values.
Notes:
- ABS (Latitude) <= 90
- ABS (Longitude) <= 180
So you can us 2 different types
- Latitude = decimal (x+2, x)
- Longitude = decimal (y+3, y)
x and y will be the desired precision. Given a metre is 1/40,000,000 of the earth's circumferemce, something like 6-8 will be enough depending on whether you're going for street or full stop accuracy in location.
If you want exact representation, and you know the scale that applies, then you can use the decimal data type.
If you work with money use DECIMAL type. It has no floating-points inaccuracy.
@MiniNamin
if you are using sql then it will also work by putting the DataType Numeric(18,4)
The benefit of floating point is that it can scale from very small to very large numbers. The cost of this, however, is that you can encounter rounding errors.
In the case that you know exactly what level of accuracy you need and will work within, the numeric / decimal types made available to you are often more appropriate. While working within the level of accuracy you specifify on creation, they will not encounter any rounding errors.
That depends on what you're using the numbers for. If these numbers are latitude and longitude, and if you don't need exact representations, then FLOAT
will work. Use DOUBLE PRECISION
for more accuracy.
But for exact representations, use DECIMAL
or NUMERIC
. Or INT
or one of its different sizes, if you'll never have fractions.
精彩评论