📄 numberutil.java
字号:
package cn.js.fan.util;
import java.text.DecimalFormat;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class NumberUtil {
public NumberUtil() {
}
/**
* 四舍五入
* @param v 双精度输入值
* @param scale 小数点后的位数
* @return 四舍五入后的字符串
*/
public static String round(double v,int scale) {
//提供能够精确到小数点后位数的四舍五入,而java.math.round不能做到
///String temp = "#,##0.";
//String temp = "###.";//如果小数点前面为0,则不显示0
String temp = "##0.";
for (int i = 0; i < scale; i++) {
temp += "0";
}
DecimalFormat d = new DecimalFormat(temp);
return d.format(v);
}
/**
* 四舍五入人民币
* @param v 双精度值
* @return 四舍五入后的人民币
*/
public static String roundRMB(double v) {
String temp = "##0.00";
DecimalFormat d = new DecimalFormat(temp);
return d.format(v);
}
/**
* 四舍五入至人民币分
* @param v 双精度输入值
* @param scale 小数点后的位数
* @return 四舍五入后的字符串
*/
public static String roundRMB2Feng(double v) {
//提供能够精确到小数点后位数的四舍五入,而java.math.round不能做到
String temp = "##0.";
DecimalFormat d = new DecimalFormat(temp);
d.setDecimalSeparatorAlwaysShown(false);//去掉小数点
return d.format(v*100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -