Skip to content

Commit

Permalink
Merge pull request #159 from eurofurence/issue-158-number-formatting
Browse files Browse the repository at this point in the history
fix(#158): use double for currency formatting not float
  • Loading branch information
Jumpy-Squirrel authored May 27, 2024
2 parents 3628fbe + bc7c511 commit 1fd3cf7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public String getAmount() {
if (Transaction.TransactionType.PAYMENT.getValue().equals(found.get(count).transactionType)) {
Transaction.Amount amount = found.get(count).amount;
if (amount != null) {
return Util.toDecimals(amount.grossCent / 100.0f);
return Util.toCurrencyDecimals(amount.grossCent);
} else {
return "???";
}
Expand All @@ -352,7 +352,7 @@ public String getAmountDue() {
if (Transaction.TransactionType.DUE.getValue().equals(found.get(count).transactionType)) {
Transaction.Amount amount = found.get(count).amount;
if (amount != null) {
return Util.toDecimals(amount.grossCent / 100.0f);
return Util.toCurrencyDecimals(amount.grossCent);
} else {
return "???";
}
Expand Down
4 changes: 2 additions & 2 deletions src/java/org/eurofurence/regsys/web/forms/FormHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static boolean testEmail(Page page, String input, final String field) {
return Util.testEmail(page::addError, input, field);
}

public static String toDecimals(float f) {
return Util.toDecimals(f);
public static String toDecimals(double d) {
return Util.toDecimals(d);
}

public static String toCurrencyDecimals(Long cents) {
Expand Down
8 changes: 0 additions & 8 deletions src/java/org/eurofurence/regsys/web/forms/InputForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,18 +585,10 @@ public boolean showManualDues() {

// attribute forwarders

private String str(int i) {
return Integer.toString(i);
}

private String str(long i) {
return Long.toString(i);
}

private String str(float f) {
return FormHelper.toDecimals(f);
}

public String getId() {
return str(nvl(attendee.id));
}
Expand Down
8 changes: 4 additions & 4 deletions src/java/org/eurofurence/regsys/web/forms/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,19 @@ public static boolean testEmail(Consumer<String> errors, String input, final Str

// Other data conversion helpers

public static String toDecimals(float f) {
public static String toDecimals(double d) {
DecimalFormat format = new DecimalFormat("0.00");
String res = format.format(f);
String res = format.format(d);
if (res != null) {
res = res.replace(',', '.'); // damn i8n
res = res.replace(',', '.'); // damn i8n
}
return res;
}

public static String toCurrencyDecimals(Long cents) {
if (cents == null)
return "UNKNOWN";
return toDecimals(cents/100f);
return toDecimals(cents/100d);
}

public static float toFloat(String s) {
Expand Down

0 comments on commit 1fd3cf7

Please sign in to comment.