I encountered this problem, which was that I couldn't add an integer to a BigDecimal. In the code, I looked at the error and it said "bad operand types for binary operator '+'". How do I add integer to BigDecimal? (Represented in code as 1 + sqf)
BigDecimal sqf = new BigDecimal(Math.sqrt(5));
sqf.setScale(100);
BigDecimal bd = new BigDecimal((1 + sqf) / 2); //Error here (1 + sqf)
bd.setScale(100);
System.out.println(isBuzzNumber(77707));
System.out.println(findHypotenuse(9, 10));
System.out.println("Phi (φ) = " + bd);
BigDecimal bd = BigDecimal.ONE.add(sqf).divide(new BigDecimal(2))
Standard operators apply to primitives only.
BigDecimal
instance as operand.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With