Chinaunix首页 | 论坛 | 博客
  • 博客访问: 159228
  • 博文数量: 56
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 593
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-18 09:59
文章分类

全部博文(56)

文章存档

2019年(1)

2018年(26)

2016年(1)

2015年(6)

2014年(22)

我的朋友

分类: Java

2018-07-05 18:07:38




点击(此处)折叠或打开

  1. import java.math.BigDecimal;

  2. /**
  3.  * 基础类型 工具类
  4.  * Created by beifang on 17/3/8.
  5.  */
  6. public class NumberUtil {

  7.     /**
  8.      * null 或者 == 0
  9.      * @param num
  10.      * @return
  11.      */
  12.     public static boolean isEmpty(Integer num) {
  13.         if(num == null || num == 0) {
  14.             return true;
  15.         }
  16.         return false;
  17.     }

  18.     /**
  19.      * null 或者 == 0
  20.      * @param num
  21.      * @return
  22.      */
  23.     public static boolean isNotEmpty(Integer num) {
  24.         return !isEmpty(num);
  25.     }

  26.     public static boolean isEmpty(Long num) {
  27.         if(num == null || num == 0) {
  28.             return true;
  29.         }
  30.         return false;
  31.     }

  32.     public static boolean isEmpty(Byte num) {
  33.         if(num == null || num == 0) {
  34.             return true;
  35.         }
  36.         return false;
  37.     }

  38.     /**
  39.      * 判断BigDecimal是否是0
  40.      * @param num
  41.      * @return
  42.      */
  43.     public static boolean isEmpty(BigDecimal num) {
  44.         if(num == null || num.compareTo(BigDecimal.ZERO)==0) {
  45.             return true;
  46.         }
  47.         return false;
  48.     }

  49.     /**
  50.      * null 或者 == 0
  51.      * @param num
  52.      * @return
  53.      */
  54.     public static boolean isNotEmpty(Long num) {
  55.         return !isEmpty(num);
  56.     }

  57.     /**
  58.      * 格式化金额
  59.      * @param amount
  60.      * @return
  61.      */
  62.     public static BigDecimal formatAmount(BigDecimal amount){
  63.         if(isEmpty(amount)){
  64.             return null;
  65.         }
  66.         return amount;
  67.     }


  68. }

阅读(1586) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~