Home »
Java »
Java Reference »
Java BigDecimal Class
Java BigDecimal movePointLeft() Method with Example
BigDecimal Class max() method: Here, we are going to learn about the max() method of BigDecimal Class with its syntax and example.
Submitted by Preeti Jain, on May 04, 2020
BigDecimal Class max() method
Syntax:
public BigDecimal movePointLeft(int number);
Parameter(s):
- int number – represents the number of places to shift the decimal point to the left in 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 left.
Example:
// Java program to demonstrate the example
// of BigDecimal movePointLeft(int number) method of BigDecimal
import java.math.*;
public class MovePointLeftOfBD {
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 left i.e.1654.238
// so it returns 0.1654238 because decimal moves
// 4 places to the left
BigDecimal left_shift = b_dec1.movePointLeft(4);
System.out.println("b_dec1.movePointLeft(4): " + left_shift);
// move the decimal point of the given
// number of places to the left i.e.100.24
// so it returns 1002.4 but here decimal moves
// 1 places to the right because the given
// parameter is negative
left_shift = b_dec2.movePointLeft(-1);
System.out.println("b_dec2.movePointLeft(-1): " + left_shift);
}
}
Output
b_dec1.movePointLeft(4): 0.1654238
b_dec2.movePointLeft(-1): 1002.4