Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 2032846

Browse files
author
Evgenii Kanivets
committed
#93[30m]. Fix rounded price when viewing record.
1 parent 5c29e38 commit 2032846

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/record/AddRecordActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.ArrayList;
3636
import java.util.Date;
3737
import java.util.List;
38+
import java.util.Locale;
3839

3940
import javax.inject.Inject;
4041

@@ -105,7 +106,7 @@ protected void initViews() {
105106
if (mode == Mode.MODE_EDIT) {
106107
etTitle.setText(record.getTitle());
107108
if (record.getCategory() != null) etCategory.setText(record.getCategory().getName());
108-
etPrice.setText(formatController.formatAmount(record.getFullPrice()));
109+
etPrice.setText(formatController.formatPrecisionNone(record.getFullPrice()));
109110
}
110111

111112
presentSpinnerAccount();

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/FormatController.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,31 @@ public FormatController(PreferenceController preferenceController) {
2323
public String formatAmount(double amount) {
2424
switch (preferenceController.readDisplayPrecision()) {
2525
case PRECISION_MATH:
26-
return String.format(Locale.getDefault(), "%d", Math.round(amount));
26+
return formatPrecisionMath(amount);
2727

2828
case PRECISION_INT:
29-
return String.format(Locale.getDefault(), "%d", (int) amount);
29+
return formatPrecisionInt(amount);
3030

3131
case PRECISION_NONE:
32-
return String.format(Locale.getDefault(), "%.2f", amount);
32+
return formatPrecisionNone(amount);
3333

3434
default:
35-
return String.format(Locale.getDefault(), "%d", Math.round(amount));
35+
return formatPrecisionMath(amount);
3636
}
3737
}
3838

39+
public String formatPrecisionMath(double amount) {
40+
return String.format(Locale.getDefault(), "%d", Math.round(amount));
41+
}
42+
43+
public String formatPrecisionInt(double amount) {
44+
return String.format(Locale.getDefault(), "%d", (int) amount);
45+
}
46+
47+
public String formatPrecisionNone(double amount) {
48+
return String.format(Locale.getDefault(), "%.2f", amount);
49+
}
50+
3951
public String formatSignedAmount(double amount) {
4052
return (amount >= 0.0 ? "+ " : "- ") + formatAmount(Math.abs(amount));
4153
}

0 commit comments

Comments
 (0)