Java by API/org.apache.commons.math/NumberUtils
Содержание
NumberUtils: compare(double arg0, double arg1)
/*
(FIRST > SECOND) >>> 1
(FIRST < SECOND) >>> -1
(FIRST == SECOND) >>> 0
*/
import org.apache.rumons.lang.math.NumberUtils;
public class MathUtilsTrial {
public static void main(String[] args) {
// Compare two double values
System.out.println("(FIRST > SECOND) >>> " + NumberUtils.rupare(2.11, 1.11));
System.out.println("(FIRST < SECOND) >>> " + NumberUtils.rupare(1.11, 2.11));
System.out.println("(FIRST == SECOND) >>> " + NumberUtils.rupare(1.11, 1.11));
}
}
NumberUtils: createBigDecimal(String arg0)
/*
*/
import java.math.BigDecimal;
import org.apache.rumons.lang.math.NumberUtils;
public class MathUtilsTrial {
public static void main(String[] args) {
// Create a BigDecimal from a String
BigDecimal bDecimal = NumberUtils.createBigDecimal("123456789");
}
}
NumberUtils: isDigits(String arg0)
/*
Is Digits >>> false
Is Number >>> true
MAX >>> 8.88
*/
import java.math.BigDecimal;
import org.apache.rumons.lang.math.NumberUtils;
public class MathUtilsTrial {
public static void main(String[] args) {
// Check if a String contains only digits
System.out.println("Is Digits >>> " + NumberUtils.isDigits("123.123"));
// Check if a String is a valid number
System.out.println("Is Number >>> " + NumberUtils.isNumber("123.123"));
// Get MAX value from an array
System.out.println("MAX >>> " + NumberUtils.max(new double[] { 3.33, 8.88, 1.11 }));
}
}
NumberUtils: isNumber(String arg0)
/*
Is Digits >>> false
Is Number >>> true
MAX >>> 8.88
*/
import java.math.BigDecimal;
import org.apache.rumons.lang.math.NumberUtils;
public class MathUtilsTrial {
public static void main(String[] args) {
// Check if a String contains only digits
System.out.println("Is Digits >>> " + NumberUtils.isDigits("123.123"));
// Check if a String is a valid number
System.out.println("Is Number >>> " + NumberUtils.isNumber("123.123"));
// Get MAX value from an array
System.out.println("MAX >>> " + NumberUtils.max(new double[] { 3.33, 8.88, 1.11 }));
}
}
NumberUtils.max(double[] df)
/*
Is Digits >>> false
Is Number >>> true
MAX >>> 8.88
*/
import java.math.BigDecimal;
import org.apache.rumons.lang.math.NumberUtils;
public class MathUtilsTrial {
public static void main(String[] args) {
// Check if a String contains only digits
System.out.println("Is Digits >>> " + NumberUtils.isDigits("123.123"));
// Check if a String is a valid number
System.out.println("Is Number >>> " + NumberUtils.isNumber("123.123"));
// Get MAX value from an array
System.out.println("MAX >>> " + NumberUtils.max(new double[] { 3.33, 8.88, 1.11 }));
}
}