这个 JAVA数学大十进制。最大值(大十进制值) 方法用于比较两个BigDecimal值并返回 最大限度 两个人中的一个。这与Java中的BigDecimal max()方法相反。
null
语法:
public BigDecimal max(BigDecimal val)
参数: 该函数接受一个BigDecimal对象 瓦尔 作为参数,其值与 这 BigDecimal对象,并返回最大值。
返回值: 此方法返回BigDecimal,其值大于 这 大十进制和 瓦尔 .如果两者相等, 这 返回BigDecimal。
例如:
Input : a = 17.000041900, b = 17.0000418999 Output : 17.000041900 Input : a = 235900000146, b = 236000000000 Output : 236000000000
下面的程序将演示BigDecimal类的max()函数。
项目1:
// Java program to illustrate use of // BigDecimal max() function in Java import java.math.*; public class GFG { public static void main(String[] args) { // create 2 BigDecimal objects BigDecimal a, b; a = new BigDecimal( "235900000146" ); b = new BigDecimal( "236000000000" ); // print the maximum value System.out.println( "Maximum Value among " + a + " and " + b + " is " + a.max(b)); } } |
输出:
Maximum Value among 235900000146 and 236000000000 is 236000000000
项目2:
// Java program to illustrate use of BigDecimal max() // to display maximum length among two strings in Java import java.math.*; public class GFG { public static void main(String[] args) { // Create 2 BigDecimal objects BigDecimal a, b; String s = "GeeksforGeeks" ; String str = "GeeksClasses" ; int l1, l2; l1 = s.length(); l2 = str.length(); a = new BigDecimal(l1); b = new BigDecimal(l2); // Print the respective lengths System.out.println( "Length of string " + s + " is " + a); System.out.println( "Length of string " + str + " is " + b); // Print the maximum value System.out.println( "Maximum length is " + a.max(b)); } } |
输出:
Length of string GeeksforGeeks is 13 Length of string GeeksClasses is 12 Maximum length is 13
参考: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#max()
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END