Online Java Compiler By
JavaTpoint.com
import java.math.BigDecimal; import java.math.MathContext; public class BigdecimalNegateExample3 { public static void main(String[] args) { // Creating BigDecimal object BigDecimal bdValue, negatedValue; // Assign value to BigDecimal objects bdValue = new BigDecimal("-18.5414"); // Assigning value in MathContext object MathContext mc = new MathContext(4); //it returns negated BigDecimal value negatedValue=bdValue.negate(mc) ; //Displaying negated value System.out.println( "Negated value of " +bdValue+" rounded by 4 is = " +negatedValue ); } }
Output