1.在java后台中进行转换
(1)使用BigDecimal类
double num=8.8888888E10;
String str=new BigDecimal(num).toString();
(2)使用DecimalFormat类
double num=8.8888888E10;
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="8.8888888E10" pattern="#.##" minFractionDigits="2" > </fmt:formatNumber>
(2)使用js脚本
var num=8.8888888E10;var str=parseFloat(num).toString();
本文介绍在Java后台及JSP页面上处理数值转换的方法。包括使用BigDecimal和DecimalFormat类进行精确转换,在JSP中利用JSTL标签fmt:formatNumber及JavaScript脚本实现格式化显示。

3009

被折叠的 条评论
为什么被折叠?



