MessageFormat格式化数字】的更多相关文章

使用MessageFormat格式化数字,有一个很隐蔽的技巧点: public static void main(String[] args) { MessageFormat mf = new MessageFormat("{0,number,#.##},{0,number,#.#}"); Object[] objs = {new Double(3.1415)}; String result = mf.format(objs); // result now equals "3…
java.text.MessageFormat格式化字符串时的小技巧 public static void main(String[] args) throws InterruptedException { MessageFormat form = new MessageFormat( "{2,date,yyyy-MM-dd HH:mm:ss.SSS} The disk \"{1}\" contains {0,number,#.##} file(s).{3}");…
DecimalFormat可以用来格式化数字,例如用来设定保留多少位小数.设定数字分隔符等. 说方法之前,先介绍一下其常用的几个模式占位符: 0 一个数字# 一个数字,不包括 0. 小数的分隔符的占位符, 分组分隔符的占位符 这里用一个简单的例子来说明其使用方法: public static void main(String[] args) { DecimalFormat df1 = new DecimalFormat("#.#"); DecimalFormat df2 = new D…
格式化数字,格式化金额: function number_format(number, decimals, dec_point, thousands_sep) { /* * 参数说明: * number:要格式化的数字 * decimals:保留几位小数 * dec_point:小数点符号 * thousands_sep:千分位符号 * */ number = (number + '').replace(/[^0-9+-Ee.]/g, ''); var n = !isFinite(+number…
当时的要求是在jsp页面中计算百分比 实现方法 1.引入Jstl的fmt指令 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 2.具体实现:type百分比,value要格式化的数字,maxIntegerDigits保留小数点后几位 <fmt:formatNumber type=" /> 奉上<fmt:formatNumber>标签详细 属性…
<? require("setup.php"); define('PAGETITLE','pagtitle'); function insert_top($lid,$sid) { echo "insert function"; } $smarty=new SmartyRebuild(); $smarty->assign('name','Linux'); $smarty->assign('title','在线有有要有和蔼是是非非要要'); $smar…
PHP保留小数点后2位的函数number_format number_format(带小数点的书,小数点后保留的位数) number_format(8.3486,2);  //取得小数点后2位有效数//结果是 8.35 注意是四舍五入的保留 number_format(8.3486,3);//结果是 8.349 number_format(83486.54543,3);//结果是83,486.545 ,注意,多了一个逗号"," 定义和用法 number_format() 函数通过千位分…
jsp页面格式化数字或时间 转载自: http://blog.csdn.net/hakunamatata2008/archive/2011/01/21/6156203.aspx Tags fmt:requestEncoding fmt:setLocale fmt:timeZone fmt:setTimeZone fmt:bundle fmt:setBundle fmt:message fmt:param fmt:formatNumber fmt:parseNumber fmt:formatDat…
php格式化数字:位数不足前面加0补足 php格式化数字:位数不足前面加0补足 感谢:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/12/16/2290585.html 先实例,后讲解 PHP代码 <?php        $var=sprintf("%04d", 2);//生成4位数,不足前面补0        echo $var;//结果为0002    ?>  PHP字符串sprintf()函数 语法 s…
js 格式化数字,格式化金额: function number_format(number, decimals, dec_point, thousands_sep) { /* * 参数说明: * number:要格式化的数字 * decimals:保留几位小数 * dec_point:小数点符号 * thousands_sep:千分位符号 * */ number = (number + '').replace(/[^0-9+-Ee.]/g, ''); var n = !isFinite(+num…