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:
- use
roundfunction:insert test select round(89.56/3, 4), round 4 decimal places. - use
stringdatatype. sqlite automatically convertnumericmathematical operations. - use
integerdatatype, , store of values multiplied 10 000, ie. 29.8533 => 298533. can divide again when retrieve value convert proper magnitude.
Comments
Post a Comment