sqlite3 - how to make the inserted data 4 digits in decimal part? -


i have create db

sqlite3  e:\\tmp.db 

and create table.

create table test(value decimal(8,4)) 

when insert data , data contain many digits in decimal part 4.

insert test select  89.56/3 ; select * test 

i got number : 29.853333333333335 ,how can insert 29.8533 test table?

according sqlite documentation, decimal(m,n) datatype stored numeric, converted sqlite engine sees fit optimize storage.

since inputting floating point value, sqlite storing such, , since floating point values cannot represent values exactly, ending approximation instead.

if must store value precision, have 3 options:

  1. use round function: insert test select round(89.56/3, 4), round 4 decimal places.
  2. use string datatype. sqlite automatically convert numeric mathematical operations.
  3. use integer datatype, , store of values multiplied 10 000, ie. 29.8533 => 298533. can divide again when retrieve value convert proper magnitude.

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -