1.在java后台中进行转换
a.使用BigDecimal类
double num=8.2347983984297E7;String str=new BigDecimal(num).toString();
注意:以上方式转换之后的可能不是你想要的模样,而是酱紫——82347983.9842970073223114013671875,原因请参考下方用法链接。
想要数值恢复原样需要使用BigDecimal的String参数构造,而不是上面的Double参数构造,解决方案如下(注意红色部分):
方式A:double num=8.2347983984297E7;String str=new BigDecimal(num+"").toString();
方式B:Double num=8.2347983984297E7;结果就成了你想要的样子:82347983.984297String str=new BigDecimal(num.toString()).toString();
b.使用DecimalFormat类
double num=8.8888888E10;String str=new DecimalFormat("0.00").format(num);//注意,这种方式是保留几位小数
2.在jsp页面中进行转换
a.使用jstl标签fmt:formatNumber
导入:<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>使用 :<fmt:formatNumber value="8.8888888E10" pattern="#.##" minFractionDigits="2" > </fmt:formatNumber>
参考用法: 参考
b.使用js脚本
var num=8.8888888E10;var str=parseFloat(num).toString();