1.java后台
(1)使用BigDecimal类
方式一:String str=new BigDecimal(num+"").toString();
方式二:String str=new BigDecimal(num.toString()).toString();
(2)使用DecimalFormat类
//注意,这种方式是保留几位小数
String str=new DecimalFormat("0.00").format(num);
2.JSP页面
(1)使用jstl标签fmt:formatNumber
导入:<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
使用:<fmt:formatNumber value="num " pattern="#.##" minFractionDigits="2" > </fmt:formatNumber>
(2)使用js脚本
var str=parseFloat(num).toString();
<fmt:formatNumber> 亲测可用。
作者:飞扬的指间沙
来源:CSDN
原文:https://blog.csdn.net/hk0701/article/details/72763587