BigDecimal stripTrailingZeros() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.math.BigDecimal.stripTrailingZeros() is an inbuilt method in Java that returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. So basically the function trims off the trailing zero from the BigDecimal value. Syntax: public BigDecimal stripTrailingZeros() Parameter: This method does not accepts any parameter. Return value: This method returns a numerical value equal to the BigDecimal with all the trailing zeros being removed. Examples: Input: 785.000 Output: 785 Input: 125500000 Output: 1.255E+8 Below programs illustrate the working of the above mentioned method: Program 1: Java // Program to demonstrate stripTrailingZeros() method of BigDecimal import java.math.*; public class Gfg { public static void main(String[] args) { BigDecimal b1 = new BigDecimal("785.000"); BigDecimal b2 = new BigDecimal("125500"); // Assigning the result of stripTrailingZeros method // to BigDecimal objects b3, b4 BigDecimal b3 = b1.stripTrailingZeros(); BigDecimal b4 = b2.stripTrailingZeros(); // print b3, b4 values System.out.println(b1 + " after removing trailing zeros " + b3); System.out.println(b2 + " after removing trailing zeros " + b4); } } Output: 785.000 after removing trailing zeros 785 125500 after removing trailing zeros 1.255E+5 Program 2: Java // Program to demonstrate stripTrailingZeros() method of BigDecimal import java.math.*; public class gfg { public static void main(String[] args) { BigDecimal b1 = new BigDecimal("785.00000"); BigDecimal b2 = new BigDecimal("125500000"); // Assigning the result of stripTrailingZeros method // to BigDecimal objects b3, b4 BigDecimal b3 = b1.stripTrailingZeros(); BigDecimal b4 = b2.stripTrailingZeros(); // Printing b3, b4 values System.out.println(b1 + " after removing trailing zeros " + b3); System.out.println(b2 + " after removing trailing zeros " + b4); } } Output: 785.00000 after removing trailing zeros 785 125500000 after removing trailing zeros 1.255E+8 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#stripTrailingZeros() Comment More infoAdvertise with us Next Article BigDecimal stripTrailingZeros() Method in Java T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-Functions java-math Java-BigDecimal Java-math-package +2 More Practice Tags : JavaMisc Similar Reads BigDecimal toBigInteger() Method in Java The java.math.BigDecimal.toBigInteger() is an inbuilt method in java that converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long. Any fractional part of this BigDecimal will be discarded. This conversion can lose information a 2 min read BigDecimal scale() Method in Java The java.math.BigDecimal.scale() is an inbuilt method in java that returns the scale of this BigDecimal. For zero or positive value, the scale is the number of digits to the right of the decimal point. For negative value, the unscaled value of the number is multiplied by ten to the power of the nega 2 min read BigDecimal min() Method in Java The java.math.BigDecimal.min(BigDecimal val) method in Java is used to compare two BigDecimal values and return the minimum of the two. Syntax: public BigDecimal min(BigDecimal val) Parameters: The function accepts a BigDecimal object val as parameter whose value is compared with that of this BigDec 2 min read BigDecimal toBigIntegerExact() Method in Java The java.math.BigDecimal.toBigIntegerExact() is an inbuilt method in java that converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part. Syntax: public BigInteger toBigIntegerExact() Parameters: The method does n 2 min read BigDecimal signum() Method in Java The java.math.BigDecimal.signum() is an inbuilt method in Java that returns the signum function of this BigDecimal. The sign function or signum function is an odd mathematical function that extracts the sign of a real number. In mathematical expressions, the sign function is often represented as sgn 2 min read BigDecimal shortValueExact() Method in Java The java.math.BigDecimal.shortValueExact() is an inbuilt method in java that converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown. Syntax: public s 2 min read BigDecimal ulp() Method in Java The java.math.BigDecimal.ulp() is an inbuilt method in Java that returns the size of an ulp(unit in the last place) of this BigDecimal. An ulp of a nonzero BigDecimal value is defined as the positive distance between this value and the BigDecimal value next larger in magnitude with the same number o 2 min read BigDecimal movePointRight() Method in Java Prerequisite : BigDecimal Basics The java.math.BigDecimal.movePointRight(int n) method is used to move the decimal point of the current BigDecimal by 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) 2 min read BigDecimal movePointLeft() Method in Java prerequisite : BigDecimal Basics The java.math.BigDecimal.movePointLeft(int n) method is used to move the decimal point of the current BigDecimal by 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 Bi 2 min read BigDecimal toString() Method in Java with Examples The java.math.BigDecimal.toString() method is used to represent the current BigDecimal by which this method is called into String form, using scientific notation if an exponent is needed. It is done by following steps: A standard canonical string form of the BigDecimal is created by converting the a 3 min read Like