Example usage for java.math BigDecimal negate

List of usage examples for java.math BigDecimal negate

Introduction

In this page you can find the example usage for java.math BigDecimal negate.

Prototype

public BigDecimal negate(MathContext mc) 

Source Link

Document

Returns a BigDecimal whose value is (-this) , with rounding according to the context settings.

Usage

From source file:Main.java

public static void main(String[] args) {

    MathContext mc = new MathContext(4);// 4 precision

    // assign value to bg1
    BigDecimal bg1 = new BigDecimal("123.1234");

    // assign negate value of bg1 to bg2 using mc
    BigDecimal bg2 = bg1.negate(mc);

    System.out.println(bg2);/*from  w  w  w .  ja  va  2s  .c  om*/
}