Skip to content

Commit

Permalink
FINERACT-1971: added automation tests for repayment schedules with la…
Browse files Browse the repository at this point in the history
…rge charge amounts
  • Loading branch information
Rustam Zeinalov committed Feb 26, 2025
1 parent c2c6485 commit 1402fb3
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ public static LocalDate now() {
return LocalDate.now(Clock.systemUTC());
}

/**
* A record that formats a double value based on whether it's a whole number or not.
* <p>
* If the value is a whole number, the output will have one decimal place (e.g., 16.0). Otherwise, it will have two
* decimal places (e.g., 16.90), but if the second decimal place is zero, it will be removed (so 16.90 becomes
* 16.9).
*/
public record DoubleFormatter(double value) {

public String format() {
boolean isWholeNumber = (value % 1.0 == 0);

String result = isWholeNumber ? String.format("%.1f", value) : String.format("%.2f", value);

// For non-whole numbers, remove trailing '0' if it exists
if (!isWholeNumber && result.endsWith("0")) {
result = result.substring(0, result.length() - 1);
}
Expand Down

0 comments on commit 1402fb3

Please sign in to comment.