- Java.math package classes
- Java.math - Home
- Java.math - BigDecimal
- Java.math - BigInteger
- Java.math - MathContext
- Java.math package extras
- Java.math - Enumerations
- Java.math - Discussion
Java.math.BigDecimal.movePointLeft() Method
Description
The java.math.BigDecimal.movePointLeft(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the scale. If n is negative, the call is equivalent to movePointRight(-n).
The BigDecimal returned by this call has value (this × 10-n) and scale max(this.scale()+n, 0).
Declaration
Following is the declaration for java.math.BigDecimal.movePointLeft() method.
public BigDecimal movePointLeft(int n)
Parameters
n − Number of places to move the decimal point to the left.
Return Value
This method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.
Exception
ArithmeticException − If scale overflows.
Example
The following example shows the usage of math.BigDecimal.movePointLeft() method.
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 ); } }
Let us compile and run the above program, this will produce the following result −
After moving the Decimal point 123.23 is 0.12323 After moving the Decimal point 12323 is 1232300