Permalink
Browse files

Don't compare floating point numbers using ==

  • Loading branch information...
1 parent d1d638a commit 4ac9ba536ac78dec88f170113bb754bff45ea267 @BalusC BalusC committed Jan 12, 2017
Showing with 1 addition and 1 deletion.
  1. +1 −1 src/main/java/org/omnifaces/el/functions/Numbers.java
@@ -248,7 +248,7 @@ private static String formatBaseUnit(Number number, int base, Integer fractions,
private static String formatBase(BigDecimal decimal, int base, Integer fractions, boolean iec, String unit) {
int exponent = (int) (Math.log(decimal.longValue()) / Math.log(base));
BigDecimal divisor = BigDecimal.valueOf(Math.pow(base, exponent));
- BigDecimal divided = (divisor.doubleValue() == 0.0) ? divisor : decimal.divide(divisor);
+ BigDecimal divided = (divisor.signum() == 0) ? divisor : decimal.divide(divisor);
int maxfractions = (fractions != null) ? fractions : (PRECISION - String.valueOf(divided.longValue()).length());
BigDecimal formatted;

0 comments on commit 4ac9ba5

Please sign in to comment.