Skip to content

Commit

Permalink
fix wrong amounts being saved, when decimals != 2, closes #79 (#81)
Browse files Browse the repository at this point in the history
* fix wrong amounts being saved, when decimals != 2, closes #79

* remove implicit cast to narrower type

Co-authored-by: Marmo <Marmo@users.noreply.github.com>
  • Loading branch information
Marmo and Marmo authored Jan 6, 2022
1 parent 0efab7a commit 4e5aff6
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ public void onSaveTransactionAction() {

// parse amount
// user is expected to enter something like "10.05"(€/$/...) and we want to store 1005 (format is enforced by AmountTextWatcher)
if (isMonetary) factor *= 100;
// OR "10" 10
// OR "10.1" 101
// OR "10.050" 10050
if (isMonetary) factor *= Double.valueOf(Math.pow(10, Utilities.getNrOfDecimals(requireContext()))).intValue();
int amount;
try {
amount = Utilities.nextInt(factor * Utilities.parseAmount(editAmount.getText().toString()));
Expand Down

0 comments on commit 4e5aff6

Please sign in to comment.