java 最近将工作中用到的工具总结数字工具方法封装。最近将工作中用到一些工具类总结了一下,写了一个日期类发出来供大家一起学习参考,各位高手如果有其他的方法欢迎扩充到里面,也欢迎指出我的代码中的错误与不足,大家共同进步共同学习
此工具类用来处理数字方面的逻辑, 如返回指定位数的随机数字、Double的加减乘除精确运算、指定位数数字用“0”补齐
- 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) { }
- }
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