韩国小游戏网站,wordpress 伪静态 cdn,计算机应用技术网站开发基础知识,wordpress 添加音乐播放器java.math.BigDecimal.byteValueExact()是一个内置函数#xff0c;它将BigDecimal转换为字节并检查丢失的信息。任何大于127或小于-128的BigDecimal值都将生成异常#xff0c;因为它不适合字节范围。用法:public byte byteValueExact()参数#xff1a;该方法不接受任何参数。…java.math.BigDecimal.byteValueExact()是一个内置函数它将BigDecimal转换为字节并检查丢失的信息。任何大于127或小于-128的BigDecimal值都将生成异常因为它不适合字节范围。用法:public byte byteValueExact()参数该方法不接受任何参数。返回值此方法返回BigDecimal对象的字节值。异常如果BigDecimal具有非零小数部分(即十进制值)或超出字节结果的可能范围则此函数引发ArithmeticException。例子Input : 127Output : 127Input : -67Output : -67下面的程序将说明byteValueExact()函数的用法示例1:// Java program to demonstrate byteValueExact() methodimport java.io.*;import java.math.*;public class GFG {public static void main(String[] args){// Creating a BigDecimal objectBigDecimal b;// Creating a byte objectsbyte bt;b new BigDecimal(47);// Assigning the byte value of b to btbt b.byteValueExact();// Displaying the byte valueSystem.out.println(Exact byte value of b is bt);}}输出Exact byte value of 47 is 47示例2:// Java program to demonstrate byteValueExact() methodimport java.io.*;import java.math.*;public class GFG {public static void main(String[] args){// Creating a BigDecimal objectBigDecimal b;b new BigDecimal(-128.0564000);System.out.println(BigDecimal value : b);long roundedValue Math.round(b.doubleValue());System.out.println(Rounded value : roundedValue);// Rounding is necessary as the fractional part is not zero// as well as exceeding the byte range of -128 to 127b new BigDecimal(roundedValue);System.out.println(Byte converted value : b.byteValueExact());}}输出BigDecimal value : -128.0564000Rounded value : -128Byte converted value : -128