Home »
Java »
Java Reference »
Java BigDecimal Class
Java BigDecimal movePointRight() Method with Example
BigDecimal Class movePointRight() method: Here, we are going to learn about the movePointRight() method of BigDecimal Class with its syntax and example.
Submitted by Preeti Jain, on May 04, 2020
BigDecimal Class movePointRight() method
Syntax:
public BigDecimal movePointRight(int number);
Parameter(s):
- int number – represents the number of places to shift the decimal point to the right of this BigDecimal.
Return value:
The return type of this method is BigDecimal, it returns the BigDecimal which is similar to this BigDecimal with the decimal point shifted the given (number) of places to the right.
Example:
// Java program to demonstrate the example
// of BigDecimal movePointRight(int number) method of BigDecimal
import java.math.*;
public class MovePointRightOfBD {
public static void main(String args[]) {
// Initialize two variables and both
// are of "String" type
String val1 = "1654.238";
String val2 = "100.24";
// Initialize two BigDecimal objects
BigDecimal b_dec1 = new BigDecimal(val1);
BigDecimal b_dec2 = new BigDecimal(val2);
// move the decimal point of the given
// number of places to the right i.e.1654.238
// so it returns 165423.8 because decimal moves
// 2 places to the right
BigDecimal right_shift = b_dec1.movePointRight(2);
System.out.println("b_dec1.movePointRight(2): " + right_shift);
// move the decimal point of the given
// number of places to the right i.e.100.24
// so it returns 1.0024 but here decimal moves
// 2 places to the left because here the given
// parameter is negative
right_shift = b_dec2.movePointRight(-2);
System.out.println("b_dec2.movePointRight(-2): " + right_shift);
}
}
Output
b_dec1.movePointRight(2): 165423.8
b_dec2.movePointRight(-2): 1.0024