- 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.movePointRight() Method
Description
The java.math.BigDecimal.movePointRight(int n) returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right. If n is non-negative, the call merely subtracts n from the scale. If n is negative, the call is equivalent to movePointLeft(-n).
The BigDecimal returned by this call has value (this × 10n) and scale max(this.scale()-n, 0).
Declaration
Following is the declaration for java.math.BigDecimal.movePointRight() method.
public BigDecimal movePointRight(int n)
Parameters
n − Number of places to move the decimal point to the right.
Return Value
This method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.
Exception
ArithmeticException − If scale overflows.
Example
The following example shows the usage of math.BigDecimal.movePointRight() 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.movePointRight(3); // 3 places right bg4 = bg2.movePointRight(-2);// 2 places left 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 123230 After moving the Decimal point 12323 is 123.23