java.math.BigDecimal.movePointLeft(int n)%uA0返回一个BigDecimal,它等效于将该值的小数点移动n位到左边。如果n为非负,则调用仅将n添加至刻度。如果n为负时,调用相当于调用movePointRight(-n)。
此调用返回的BigDecimal的值(this %uD7 10-n) 和比例max(this.scale()+n, 0).
声明
以下是java.math.BigDecimal.movePointLeft()方法的声明
public BigDecimal movePointLeft(int n)
参数
-
n%uA0- 小数点向左移动位数
返回值
此方法返回一个BigDecimal,它等效于将该值的小数点向左移动n位
异常
-
ArithmeticException%uA0- 如果刻度溢出
例子
下面的例子显示math.BigDecimal.movePointLeft()方法的用法
package com.yiibai 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