Java Data Type Tutorial - Java BigDecimal.byteValueExact()








Syntax

BigDecimal.byteValueExact() has the following syntax.

public byte byteValueExact()

Example

In the following code shows how to use BigDecimal.byteValueExact() method.

/*from  w  w w  .j  a  va  2s .co m*/
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    // assign values to bg1 and bg2
    BigDecimal bg1 = new BigDecimal("-128");
    BigDecimal bg2 = new BigDecimal("48");

    byte i1 = bg1.byteValueExact();
    byte i2 = bg2.byteValueExact();

    // print i1,i2 values
    System.out.println(i1);
    System.out.println(i2);
  }
}

The code above generates the following result.