Closed Marmo closed 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
Use
new BigDecimal(Double.toString(d)).setScale(2, RoundingMode.HALF_UP).doubleValue()
For rounding
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