public final class Numbers extends Object
Number utility 十进制:10 二进制:0B10 八进制:010 十六进制:0X10 小数点:1e-9
| 限定符和类型 | 字段和说明 |
|---|---|
static byte |
ZERO_BYTE |
static int |
ZERO_INT |
static Integer |
ZERO_INTEGER |
| 构造器和说明 |
|---|
Numbers() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
bound(Integer value,
int min,
int max)
区间取值
|
static boolean |
equals(Long a,
Integer b)
Returns the Long object is equals the Integer object
|
static String |
format(double d,
int scale)
Returns a string value of double
|
static String |
format(Object obj)
数字格式化
|
static String |
format(Object obj,
String format)
数字格式化
|
static double |
lower(double value,
int pow)
向下转单位
|
static double |
lower(double value,
int pow,
int scale) |
static List<Tuple2<Integer,Integer>> |
partition(int number,
int size)
Partition the number
partition( 0, 2) -> [(0, 0)]
partition( 2, 3) -> [(0, 0), (1, 1)]
partition( 3, 1) -> [(0, 2)]
partition( 9, 3) -> [(0, 2), (3, 5), (6, 8)]
partition(10, 3) -> [(0, 3), (4, 6), (7, 9)]
partition(11, 3) -> [(0, 3), (4, 7), (8, 10)]
partition(12, 3) -> [(0, 3), (4, 7), (8, 11)]
|
static String |
percent(double numerator,
double denominator,
int scale)
百分比
|
static String |
percent(double value,
int scale)
百分比
|
static double |
scale(Object value,
int scale)
数字精度化
|
static int[] |
slice(int quantity,
int segment)
分片
slice(0 , 2) -> [0, 0]
slice(2 , 3) -> [1, 1, 0]
slice(3 , 1) -> [3]
slice(9 , 3) -> [3, 3, 3]
slice(10, 3) -> [4, 3, 3]
slice(11, 3) -> [4, 4, 3]
slice(12, 3) -> [4, 4, 4]
|
static int[] |
split(Long orderId,
int[] bills,
int value)
Split the bill for coupon amount
split(new int[]{249, 249, 249, 3}, 748) -> [249, 249, 248, 2] |
static double |
sum(Double a,
Double b) |
static int |
sum(Integer a,
Integer b) |
static long |
sum(Long a,
Long b) |
static boolean |
toBoolean(Object obj) |
static boolean |
toBoolean(Object obj,
boolean defaultVal) |
static byte |
toByte(Object obj) |
static byte |
toByte(Object obj,
byte defaultVal) |
static char |
toChar(Object obj) |
static char |
toChar(Object obj,
char defaultVal) |
static double |
toDouble(Object obj) |
static double |
toDouble(Object obj,
double defaultVal) |
static float |
toFloat(Object obj) |
static float |
toFloat(Object obj,
float defaultVal) |
static String |
toHex(BigInteger num)
To upper hex string and remove prefix 0
|
static int |
toInt(Object obj) |
static int |
toInt(Object obj,
int defaultVal) |
static long |
toLong(Object obj) |
static long |
toLong(Object obj,
long defaultVal) |
static short |
toShort(Object obj) |
static short |
toShort(Object obj,
short defaultVal) |
static Boolean |
toWrapBoolean(Object obj) |
static Byte |
toWrapByte(Object obj) |
static Character |
toWrapChar(Object obj) |
static Double |
toWrapDouble(Object obj) |
static Float |
toWrapFloat(Object obj) |
static Integer |
toWrapInt(Object obj) |
static Long |
toWrapLong(Object obj) |
static Short |
toWrapShort(Object obj) |
static double |
upper(double value,
int pow)
向上转单位
|
static double |
upper(double value,
int pow,
int scale) |
public static final int ZERO_INT
public static final Integer ZERO_INTEGER
public static final byte ZERO_BYTE
public static char toChar(Object obj)
public static char toChar(Object obj, char defaultVal)
public static boolean toBoolean(Object obj)
public static boolean toBoolean(Object obj, boolean defaultVal)
public static byte toByte(Object obj)
public static byte toByte(Object obj, byte defaultVal)
public static short toShort(Object obj)
public static short toShort(Object obj, short defaultVal)
public static int toInt(Object obj)
public static int toInt(Object obj, int defaultVal)
public static long toLong(Object obj)
public static long toLong(Object obj, long defaultVal)
public static float toFloat(Object obj)
public static float toFloat(Object obj, float defaultVal)
public static double toDouble(Object obj)
public static double toDouble(Object obj, double defaultVal)
public static double scale(Object value, int scale)
value - scale - public static double lower(double value,
int pow)
value - pow - public static double lower(double value,
int pow,
int scale)
public static double upper(double value,
int pow)
value - pow - public static double upper(double value,
int pow,
int scale)
public static String percent(double numerator, double denominator, int scale)
numerator - denominator - scale - public static String percent(double value, int scale)
value - scale - public static String format(double d, int scale)
d - the double valuescale - the scalepublic static int bound(Integer value, int min, int max)
value - min - max - public static int[] slice(int quantity,
int segment)
slice(0 , 2) -> [0, 0] slice(2 , 3) -> [1, 1, 0] slice(3 , 1) -> [3] slice(9 , 3) -> [3, 3, 3] slice(10, 3) -> [4, 3, 3] slice(11, 3) -> [4, 4, 3] slice(12, 3) -> [4, 4, 4]
quantity - segment - public static List<Tuple2<Integer,Integer>> partition(int number, int size)
partition( 0, 2) -> [(0, 0)] partition( 2, 3) -> [(0, 0), (1, 1)] partition( 3, 1) -> [(0, 2)] partition( 9, 3) -> [(0, 2), (3, 5), (6, 8)] partition(10, 3) -> [(0, 3), (4, 6), (7, 9)] partition(11, 3) -> [(0, 3), (4, 7), (8, 10)] partition(12, 3) -> [(0, 3), (4, 7), (8, 11)]
number - the numbersize - the sizepublic static int[] split(Long orderId, int[] bills, int value)
bills - the billsvalue - the coupon amount valuepublic static boolean equals(Long a, Integer b)
a - the Long ab - the Integer btruepublic static String toHex(BigInteger num)
num - the BigIntegerCopyright © 2023. All rights reserved.