Android greenDAO Floating point saving wrong

Hi everyone, I use the green DAO library to create and manage the database, and I have some fields in the database, for example

     Float total;

when I try to insert the values ​​25.4, it stores 25.4099998474121

Subsequently, when I retrieve the data from the database, I get 25.4099998474121, and in the end, all my calculations go wrong.

Please help me out of this

thanks

+4
source share
1 answer

When creating an Sqlite table, the value of a floating-point field type is defined as decimal (15.2). Here 2 indicates the number of decimal points, and 15 indicates the total number of valid digits.

, ,

create table testing(numberField decimal(15,2))
insert into testing values(9999999999999.99)

.

,

insert into testing values(25.4)

25.4 sqlite. , .

0

Source: https://habr.com/ru/post/1528246/


All Articles