List of utility methods to do BigDecimal from
BigDecimal | toBigDecimal(long seconds, int nanoseconds) to Big Decimal if (nanoseconds == 0L) { if (seconds == 0L) { return BigDecimal.ZERO.setScale(1); return BigDecimal.valueOf(seconds).setScale(9); return new BigDecimal(toDecimal(seconds, nanoseconds)); |
BigDecimal | toBigDecimal(Number n) Convert the given Number to a BigDecimal if (n instanceof BigDecimal) { return (BigDecimal) n; if (n instanceof BigInteger) { return new BigDecimal((BigInteger) n); return new BigDecimal(n.doubleValue()); |
BigDecimal | toBigDecimal(Number n) Converts any number to a BigDecimal, suited for comparison and (monetary) arithmetic. if (n instanceof BigDecimal) { return (BigDecimal) n; if (n instanceof Long) { return new BigDecimal((Long) n); } else if (n instanceof Integer) { return new BigDecimal((Integer) n); } else if (n instanceof Float) { ... |
BigDecimal | toBigDecimal(Number n) to Big Decimal BigDecimal bd; if (n == null) { throw new IllegalArgumentException("Your number is null"); } else if (n instanceof BigDecimal) { bd = (BigDecimal) n; } else if (n instanceof BigInteger) { bd = new BigDecimal((BigInteger) n); } else if (n instanceof Short || n instanceof Long || n instanceof Integer) { ... |
BigDecimal | toBigDecimal(Number n) Converts a number into BigDecimal representation. if (n instanceof BigDecimal) return (BigDecimal) n; return new BigDecimal(n.toString()); |
BigDecimal | toBigDecimal(Number num) to Big Decimal try { return num instanceof BigDecimal ? (BigDecimal) num : new BigDecimal(num.toString()); } catch (NumberFormatException e) { throw new NumberFormatException("Can't parse this as BigDecimal number: " + num); |
BigDecimal | toBigDecimal(Number number) Converts (almost) any number to BigDecimal . if (number instanceof BigDecimal) return (BigDecimal) number; return new BigDecimal(number.toString()); |
BigDecimal | toBigDecimal(Number number) We should convert each number to java.math.BigDecimal to compare different number types: Byte, Short, Integer, Long, Float, Double, BigDecimal, etc if (number.getClass() == Integer.class || number.getClass() == Long.class || number.getClass() == Short.class || number.getClass() == Byte.class) { return BigDecimal.valueOf(number.longValue()); } else if (number.getClass() == Double.class || number.getClass() == Float.class) { return BigDecimal.valueOf(number.doubleValue()); } else if (number.getClass() == BigDecimal.class) { return (BigDecimal) number; } else if (number.getClass() == BigInteger.class) { ... |
BigDecimal | toBigDecimal(Number number) Returns a java.math.BigDecimal representation of a given number. If the class of a number isn't one of standard Java number classes, the conversion is made through number doubleValue() method call. If a number is null then null is returned. if (number == null) return null; if (number instanceof BigDecimal) return (BigDecimal) number; if (number instanceof Long) return BigDecimal.valueOf((Long) number); if (number instanceof Integer) return BigDecimal.valueOf((Integer) number); ... |
BigDecimal | toBigDecimal(Number number) Safely converts a number to a BigInteger. String type = number.getClass().getSimpleName(); BigDecimal parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigDecimal(by.doubleValue()); break; case "Short": ... |