David Addoteye
David Addoteye

Reputation: 1641

Storing Decimal value in Websql

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.

Upvotes: 2

Views: 469

Answers (1)

drinovc
drinovc

Reputation: 551

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.

Upvotes: 1

Related Questions