Description Of BigDecimal: compareTo(BigDecimal val)
The java.math.BigDecimal.xor(BigInteger val) compares this BigDecimal with the specified BigDecimal . Two BigDecimal objects that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) < op > 0) , where < op > is one of the six comparison operators.BigDecimal.compareTo(BigDecimal val) method returns -1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val
Code Example Java BigDecimal
import java.math.BigDecimal; public class BigDecimalExam { public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("5"); BigDecimal bg2 = new BigDecimal("10"); int res = bg1.compareTo(bg2); // compare bg1 with bg2 if (res == 0) { System.out.println("Both values are equal"); } else if (res == 1) { System.out.println("First Value is greater"); } else if (res == -1) { System.out.println("Second value is greater"); } } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น