- Java.math 软件包额外信息
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigDecimal.movePointLeft() 方法
描述
java.math.BigDecimal.movePointLeft(int n) 返回一个 BigDecimal,它等同于在 decimal point 向左移动 n 位后的这个 BigDecimal。如果 n 为非负数,则调用仅仅向精度 scale 添加 n。如果 n 为负数,则调用等同于 movePointRight(-n)。
此调用返回的 BigDecimal 具有值 (this × 10-n) 和精度 scale max(this.scale()+n, 0)。
声明
以下是 java.math.BigDecimal.movePointLeft() 方法的声明。
public BigDecimal movePointLeft(int n)
参数
n − 将 decimal point 向左移动的位数。
返回值
此方法返回一个 BigDecimal,它等同于在 decimal point 向左移动 n 位后的这个 BigDecimal。
异常
ArithmeticException − 如果精度溢出。
示例
以下示例演示了 math.BigDecimal.movePointLeft() 方法的用法。
package com.tutorialspoint;
import java.math.*;
public class BigDecimalDemo {
public static void main(String[] args) {
// create 4 BigDecimal objects
BigDecimal bg1, bg2, bg3, bg4;
bg1 = new BigDecimal("123.23");
bg2 = new BigDecimal("12323");
bg3 = bg1.movePointLeft(3); // 3 points left
bg4 = bg2.movePointLeft(-2);// 2 points right
String str1 = "After moving the Decimal point " + bg1 + " is " + bg3;
String str2 = "After moving the Decimal point " + bg2 + " is " + bg4;
// print bg3, bg4 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上述程序,这将产生以下结果 −
After moving the Decimal point 123.23 is 0.12323 After moving the Decimal point 12323 is 1232300
java_math_bigdecimal.htm
广告