Java Algorithms How to - Compare BigDecimal movePointRight and scaleByPowerOfTen








Question

We would like to know how to compare BigDecimal movePointRight and scaleByPowerOfTen.

Answer

import java.math.BigDecimal;
/*www .java 2  s .c om*/
public class Main {
  public static void main(String... args) {
    long base = 12345;
    int scale = 4;

    BigDecimal number = BigDecimal.valueOf(base, scale);
    System.out.println(number);
    BigDecimal pointRight = number.movePointRight(5);
    System.out.println(pointRight + "; my scale is " + pointRight.scale());
    BigDecimal scaleBy = number.scaleByPowerOfTen(5);
    System.out.println(scaleBy + "; my scale is " + scaleBy.scale());
  }
}

The code above generates the following result.