วันจันทร์ที่ 8 กันยายน พ.ศ. 2557

Java java.math BigDecimal movePointRight(int n)

Description Of BigDecimal: movePointRight(int n)

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) .

BigDecimal.movePointRight(int n) method returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.

Code Example Java BigDecimal

import java.math.BigDecimal;

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

  BigDecimal bg3 = bg1.movePointRight(3); // 3 points right
  BigDecimal bg4 = bg2.movePointRight(-2);// 2 points left

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


yengo หรือ buzzcity

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

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