วันศุกร์ที่ 22 สิงหาคม พ.ศ. 2557

Java java.math BigDecimal stripTrailingZeros()

Description Of BigDecimal: stripTrailingZeros()

The java.math.BigDecimal.stripTrailingZeros() returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the BigDecimal value 600.0 , which has [ BigInteger , scale ] components equals to [6000, 1], yields 6E2 with [ BigInteger , scale ] components equals to [6, -2]

BigDecimal.stripTrailingZeros() method returns a numerically equal BigDecimal with any trailing zeros removed.

Code Example Java BigDecimal

import java.math.BigDecimal;

public class BigDecimalExam {
 public static void main(String[] args) {
  BigDecimal bg1 = new BigDecimal("123.000");
  BigDecimal bg2 = new BigDecimal("012300");

  BigDecimal bg3 = bg1.stripTrailingZeros();
  BigDecimal bg4 = bg2.stripTrailingZeros();

  String str1 = bg1 + " after removing trailing zeros " + bg3;
  String str2 = bg2 + " after removing trailing zeros " + bg4;

  // print bg3, bg4 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น