java 最近将工作中用到的工具总结数字工具方法封装



java 最近将工作中用到的工具总结数字工具方法封装。最近将工作中用到一些工具类总结了一下,写了一个日期类发出来供大家一起学习参考,各位高手如果有其他的方法欢迎扩充到里面,也欢迎指出我的代码中的错误与不足,大家共同进步共同学习

此工具类用来处理数字方面的逻辑, 如返回指定位数的随机数字、Double的加减乘除精确运算、指定位数数字用“0”补齐

  1. package com.wp.util;
  2. import java.math.BigDecimal;
  3. import org.apache.commons.lang.RandomStringUtils;
  4. /**
  5. * @project: WebProjectUtil
  6. * @class: NumberUtil
  7. * @describe: 此工具类用来处理数字方面的逻辑,
  8. * 如返回指定位数的随机数字、Double的加减乘除精确运算、指定位数数字用“0”补齐
  9. * @autho: Administrator
  10. * @date: 2013-6-7 下午02:26:27
  11. * @alter: Administrator
  12. * @alterDate: 2013-6-7 下午02:26:27
  13. * @alterRemark:
  14. * @version V1.0
  15. */
  16. public class NumberUtil {
  17.     private static final int DEF_DIV_SCALE = 2;
  18.     /**
  19.      * @return 返回12位随机数
  20.      */
  21.     public static String randomNumber() {   }
  22.     /**
  23.      * @param parm
  24.      * @return 返回指定位数随机数
  25.      */
  26.     public static String randomNumber(int parm) {   }
  27.     /**
  28.      * * 两个Double数相加 *
  29.      * @param v1
  30.      * @param v2
  31.      * @return Double
  32.      */
  33.     public static Double add(Double v1, Double v2) {    }
  34.     /**
  35.      * * 两个Double数相减 *
  36.      * @param v1
  37.      * @param v2
  38.      * @return Double
  39.      */
  40.     public static Double sub(Double v1, Double v2) {    }
  41.     /**
  42.      * * 两个Double数相乘 *
  43.      * @param v1
  44.      * @param v2
  45.      * @return Double
  46.      */
  47.     public static Double mul(Double v1, Double v2) {    }
  48.     /**
  49.      * * 两个Double数相除 *
  50.      * @param v1
  51.      * @param v2
  52.      * @return Double
  53.      */
  54.     public static Double div(Double v1, Double v2) {    }
  55.     /**
  56.      * * 两个Double数相除,并保留scale位小数 *
  57.      * @param v1
  58.      * @param v2
  59.      * @param scale
  60.      * @return Double
  61.      */
  62.     public static Double div(Double v1, Double v2, int scale) { }
  63.     /**
  64.      * 返回指定Double的负数
  65.      * @param v1
  66.      * @return
  67.      */
  68.     public static Double neg(Double v1) {
  69.     /**
  70.      * @Title: toFixdLengthString
  71.      * @Description: 将字符串用符号填充位数
  72.      * @param str 源字符串
  73.      * @param fixdlenth 位数
  74.      * @return String
  75.      * @throws
  76.      */
  77.     public static String toFixdLengthString(String str, int fixdlenth) {    }
  78.     /**
  79.      * @Title: toFixdLengthString
  80.      * @Description: 将数字用“0”填充位数
  81.      * @param num
  82.      * @param fixdlenth
  83.      * @return String
  84.      * @throws
  85.      */
  86.     public static String toFixdLengthString(int num, int fixdlenth) {   }
  87.     /**
  88.      * @Title: generateSpaceString
  89.      * @Description: 得到指定位数占位符
  90.      * @param length
  91.      * @return String
  92.      * @throws
  93.      */
  94.     public static String generateSpaceString(int length) {  }
  95.     /**
  96.      * @Title: generateZeroString
  97.      * @Description: 得到指定位数的“0”的占位符
  98.      * @param length
  99.      * @return String
  100.      * @throws
  101.      */
  102.     public static String generateZeroString(int length) {   }
  103. }
package com.wp.util;

import java.math.BigDecimal;

import org.apache.commons.lang.RandomStringUtils;

/**   
 * @project: WebProjectUtil   
 * @class: NumberUtil   
 * @describe: 此工具类用来处理数字方面的逻辑,
 * 如返回指定位数的随机数字、Double的加减乘除精确运算、指定位数数字用“0”补齐
 * @autho: Administrator   
 * @date: 2013-6-7 下午02:26:27
 * @alter: Administrator
 * @alterDate: 2013-6-7 下午02:26:27
 * @alterRemark: 
 * @version V1.0
 */ 
public class NumberUtil {

	private static final int DEF_DIV_SCALE = 2;

	/**
	 * @return 返回12位随机数
	 */
	public static String randomNumber() {	}

	/**
	 * @param parm
	 * @return 返回指定位数随机数
	 */
	public static String randomNumber(int parm) {	}

	/**
	 * * 两个Double数相加 *
	 * @param v1
	 * @param v2
	 * @return Double
	 */
	public static Double add(Double v1, Double v2) {	}

	/**
	 * * 两个Double数相减 *
	 * @param v1
	 * @param v2
	 * @return Double
	 */
	public static Double sub(Double v1, Double v2) {	}

	/**
	 * * 两个Double数相乘 *
	 * @param v1
	 * @param v2
	 * @return Double
	 */
	public static Double mul(Double v1, Double v2) {	}

	/**
	 * * 两个Double数相除 *
	 * @param v1
	 * @param v2
	 * @return Double
	 */
	public static Double div(Double v1, Double v2) {	}

	/**
	 * * 两个Double数相除,并保留scale位小数 *
	 * @param v1
	 * @param v2
	 * @param scale
	 * @return Double
	 */
	public static Double div(Double v1, Double v2, int scale) {	}

	/**
	 * 返回指定Double的负数
	 * @param v1
	 * @return 
	 */
	public static Double neg(Double v1) {
	/**
	 * @Title: toFixdLengthString  
	 * @Description: 将字符串用符号填充位数
	 * @param str 源字符串
	 * @param fixdlenth 位数
	 * @return String
	 * @throws 
	 */
	public static String toFixdLengthString(String str, int fixdlenth) {	}

	/**
	 * @Title: toFixdLengthString  
	 * @Description: 将数字用“0”填充位数
	 * @param num
	 * @param fixdlenth
	 * @return String
	 * @throws 
	 */
	public static String toFixdLengthString(int num, int fixdlenth) {	}

	/**
	 * @Title: generateSpaceString  
	 * @Description: 得到指定位数占位符  
	 * @param length
	 * @return String
	 * @throws 
	 */
	public static String generateSpaceString(int length) {	}

	/**
	 * @Title: generateZeroString  
	 * @Description: 得到指定位数的“0”的占位符
	 * @param length
	 * @return String
	 * @throws 
	 */
	public static String generateZeroString(int length) {	}
}

具体代码可以从这里下载:http://download.csdn.net/detail/songylwq/5538765