Marmo / debitum

free and libre IOU tracker for Android
GNU General Public License v3.0
85 stars 7 forks source link

Wrong amount saved when saving transactions with certain amounts #54

Closed Marmo closed 3 years ago

Marmo commented 3 years ago

Expected: When entering "4.60" as amount and saving a transaction with 4.60 (460 as internal db value) is created.

Actual: A transaction with 4.59 (459) is created. This also applies to amounts 1.15, 2.30, 9.20 and probably many more.

Probably related to int-casting (not rounding) the double in https://github.com/Marmo/debitum/blob/8877b6cc060c53d6f61c1b5ecf1ede2a7b6f0a00/app/src/main/java/org/ebur/debitum/ui/EditTransactionFragment.java#L310

Marmo commented 3 years ago

Use

new BigDecimal(Double.toString(d)).setScale(2, RoundingMode.HALF_UP).doubleValue()

For rounding