VOOZH about

URL: https://www.geeksforgeeks.org/java/bigdecimal-striptrailingzeros-method-in-java/

⇱ BigDecimal stripTrailingZeros() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigDecimal stripTrailingZeros() Method in Java

Last Updated : 4 Dec, 2018
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:
Output:
785.000 after removing trailing zeros 785
125500 after removing trailing zeros 1.255E+5
Program 2:
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