BigDecimal scaleByPowerOfTen() method in Java
The java.math.BigDecimal.scaleByPowerOfTen(int n) is an inbuilt method on java that returns a BigDecimal whose numerical value is equal to (this * 10n). The scale of the result is (this.scale() – n).
Syntax:
public BigDecimal scaleByPowerOfTen(int n)
Parameters:
The method accepts a single parameter n of integer type which refers to the value by which BigDecimal object is multiplied to power of ten.
Return value:This method returns the BigDecimal object of value this * 10n.
Below program illustrates the above mentioned method:
Program 1:
// Java program to demonstrate the // scaleByPowerOfTen() method import java.math.*; public class Gfg { public static void main(String[] args) { // Assign two bigecimal objects BigDecimal b1 = new BigDecimal("754.000"); BigDecimal b2 = new BigDecimal("75400"); // Assign the result of method on b1, b2 // to BigDecimal objects b3, b4 BigDecimal b3 = b1.scaleByPowerOfTen(4); BigDecimal b4 = b2.scaleByPowerOfTen(-4); // Print b3, b4 values System.out.println(b1 + " raised to power is " + b3); System.out.println(b2 + " raised to power is " + b4); } } |
754.000 raised to power is 7.54000E+6 75400 raised to power is 7.5400
Program 2:
// Java program to demonstrate the // scaleByPowerOfTen() method import java.math.*; public class Gfg { public static void main(String[] args) { // Assign two bigecimal objects BigDecimal b1 = new BigDecimal("200"); BigDecimal b2 = new BigDecimal("7540000000"); // Assign the result of method on b1, b2 // to BigDecimal objects b3, b4 BigDecimal b3 = b1.scaleByPowerOfTen(4); BigDecimal b4 = b2.scaleByPowerOfTen(-4); // Print b3, b4 values System.out.println(b1 + " raised to power is " + b3); System.out.println(b2 + " raised to power is " + b4); } } |
200 raised to power is 2.00E+6 7540000000 raised to power is 754000.0000
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#scaleByPowerOfTen(int)
Recommended Posts:
- BigDecimal plus() method in Java
- BigDecimal ulp() Method in Java
- BigDecimal min() Method in Java
- BigDecimal abs() Method in Java
- BigDecimal max() Method in Java
- BigDecimal add() Method in Java with Examples
- BigDecimal intValue() Method in Java
- BigDecimal longValueExact() Method in Java
- BigDecimal intvalueExact() Method in Java
- BigDecimal round() Method in Java
- BigDecimal scale() Method in Java
- BigDecimal multiply() Method in Java
- BigDecimal movePointRight() Method in Java
- BigDecimal movePointLeft() Method in Java
- BigDecimal stripTrailingZeros() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


