Java Code Examples for cn.hutool.core.util.NumberUtil#add()

The following examples show how to use cn.hutool.core.util.NumberUtil#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HutoolController.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
@ApiOperation("NumberUtil使用:数字处理工具类")
@GetMapping("/numberUtil")
public CommonResult numberUtil() {
    double n1 = 1.234;
    double n2 = 1.234;
    double result;
    //对float、double、BigDecimal做加减乘除操作
    result = NumberUtil.add(n1, n2);
    result = NumberUtil.sub(n1, n2);
    result = NumberUtil.mul(n1, n2);
    result = NumberUtil.div(n1, n2);
    //保留两位小数
    BigDecimal roundNum = NumberUtil.round(n1, 2);
    String n3 = "1.234";
    //判断是否为数字、整数、浮点数
    NumberUtil.isNumber(n3);
    NumberUtil.isInteger(n3);
    NumberUtil.isDouble(n3);
    return CommonResult.success(null, "操作成功");
}
 
Example 2
Source File: OrderUtil.java    From yshopmall with Apache License 2.0 2 votes vote down vote up
/**
 * 获取俩个数之间的随机数
 *
 * @param min
 * @param max
 * @return
 */
public static Double randomNumber(double min, double max) {
    return NumberUtil.add(min,
            NumberUtil.mul(Math.random(),
                    NumberUtil.sub(max, min)));
}