Skip to content

Commit

Permalink
added trimTo2Digits
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgesl committed Mar 20, 2024
1 parent 27f7abd commit 24c5c93
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/fr/jmmc/jmcs/util/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public static double trimTo1Digits(final double value) {
return ((long) (10.0 * value)) / 10.0;
}

/**
* Adjust the given double value to keep only 2 decimal digits
* @param value value to adjust
* @return double value with only 2 decimal digits
*/
public static double trimTo2Digits(final double value) {
if (!Double.isFinite(value)) {
return value;
}
return ((long) (1e2d * value)) / 1e2d;
}

/**
* Adjust the given double value to keep only 3 decimal digits
* @param value value to adjust
Expand Down

0 comments on commit 24c5c93

Please sign in to comment.