SQLite Forum

"Office Space"... I'm losing all those pennies
The IEEE-754 floating point value 16.15 is 16.149999999999998578914528.

When you "cast to int" you discard the fraction.

16.15*100 is 1614.9999999999997726263245

When you cast this value to integer (discard the fraction) the result is 1614

The %d format specifier to printf formats a float as an integer by casting to integer.

The %.0f format specifier "pretty prints for hooman consumption" the value to 0 decimal places which then prints 1615.

This is simply how floating point arithmetic works.  If you wish to ROUND the value to the nearest integer, then you should simply do so:

sqlite> select round(sum(cast('16.15' as numeric))*100, 0);
│ round(sum(cast('16.15' as numeric))*100, 0) │
│ 1615.0                                      │