Question

I made a table:

CREATE TABLE IF NOT EXISTS vehicles (
    vehicleid INT(3),
    vehiclex FLOAT(6,6),
    vehicley FLOAT(6,6),
    vehiclez FLOAT(6,6),
    vehicleaw FLOAT(6,6),
    vehiclecolor1 INT(2),
    vehiclecolor2 INT(2)
)

Now when I'm trying to insert this:

INSERT INTO vehicles (vehicleid,vehiclex,vehicley,vehiclez,vehicleaw,vehiclecolor1,vehiclecolor2)
VALUES(411,1786.9001,-1892.1359,13.4903,14.0000,0,0)

First of all, now errors, no warnings :)

I'm getting a invalid row in SQL query:

SELECT * FROM `vehicles` ORDER BY `vehicles`.`vehiclez` ASC LIMIT 0, 30 ; 

result Rows: 1

vehicleid vehiclex vehicley vehiclez vehicleaw vehiclecolor1 vehiclecolor2 411 0.999999 -0.999999 0.999999 0.999999 0 0

So, What should I do?

Was it helpful?

Solution

The first argument to FLOAT is the total number of digits, not the number of digits that can occur before the decimal point.

In your current code, the total number of digits is the same as the number of digits that can occur after the decimal point, so the numbers stored cannot be greater than 0.999999 (or less than -0.999999).

Try something like FLOAT(12, 6).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top