I have a collection of BigDecimals (in this example, a LinkedList) that I would like to add together. Is it possible to use streams for this? I noticed the...
I have this little crazy method that converts BigDecimal values into nice and readable Strings. private String formatBigDecimal(BigDecimal bd){ DecimalFormat df = new DecimalFormat(); df.setMinimumFractionDigits(3); df.setMaximumFractionDigits(3); df.setMinimumIntegerDigits(1); df.setMaximumIntegerDigits(3); df.setGroupingSize(20);...
I’m trying to round BigDecimal values up, to two decimal places. I’m using BigDecimal rounded = value.round(new MathContext(2, RoundingMode.CEILING)); logger.trace("rounded {} to {}", value, rounded); but it doesn’t do...
I have the following code in Java; BigDecimal price; // assigned elsewhere if (price.compareTo(new BigDecimal("0.00")) == 0) { return true; } What is the best way to write the...
How can I compare if BigDecimal value is greater than zero? 7 Answers 7
I have to calculate some floating point variables and my colleague suggest me to use BigDecimal instead of double since it will be more precise. But I want to...
Why does the following code raise the exception shown below? BigDecimal a = new BigDecimal("1.6"); BigDecimal b = new BigDecimal("9.2"); a.divide(b) // results in the following exception. Exception: java.lang.ArithmeticException:...