Storing Decimal value in Websql

478 views Asked by At

I am trying to store a decimal value like -0.19999999999999998 and 174.18319999453 in a WebSql database. I however get the value round to -0.2 for -0.19999999999999998 in the database.

I will like to save it as a number, not a string. thank you.

this is my table structure

    tx.executeSql("CREATE TABLE IF NOT EXISTS LOGLOCATION (id INTEGER PRIMARY KEY AUTOINCREMENT, name, lat DECIMAL(28, 20), lng DECIMAL(28, 20), desc)");

I will be glad if anyone can help, Thank you.

1

There are 1 answers

0
drinovc On BEST ANSWER

You could store decimals using TEXT data type. Use value.toString() function when inserting value into DB and parsing back to decimal using parseFloat(value).

I tried few other approaches but only this one works for me.