java、el表达式中保留小数的方法
Java中:
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class format {
double f = 111231.5585;
public void m1() {
BigDecimal bg = new BigDecimal(f);
double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(f1);
}
/**
* DecimalFormat转换最简便
*/
public void m2() {
DecimalFormat df = new DecimalFormat("#.00");
System.out.println(df.format(f));
}
/**
* String.format打印最简便
*/
public void m3() {
System.out.println(String.format("%.2f", f));
}
public void m4() {
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(f));
}
public static void main(String[] args) {
format f = new format();
f.m1();
f.m2();
f.m3();
f.m4();
}
}
111231.56
111231.56
111231.56
111,231.56
<fmt:formatNumber value="${num}" maxFractionDigits="0"/>
<fmt:formatNumber value="${failAllSum}" pattern="#,###.##" />
java、el表达式中保留小数的方法的更多相关文章
- java EL表达式中${param.name}详细
在浏览器地址输入,表示传入一个参数test,值为123 URL:http://localhost:8888/Test/index.jsp?test=123 <body> ${test} $ ...
- Js 和 PHP 中保留小数点后X位数的方法 toFixed、round、number_format、sprintf
在 Javacript 中保留小数点后两位数的方法为 toFixed(2),其中的2为保留两位,写多少就保留多少了,满5进1. Javacript例子: var num = 24.54789523; ...
- EL表达式中fn函数 (转载)
JSTL 使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请求参数或者context以及 session中的数据的访问非常方便,但是我们在实际应用中经常需 ...
- EL表达式中如何截取字符串
EL表达式中如何截取字符串 可以截取,用fn函数:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/ ...
- EL表达式中引用隐式变量
除了在jsp中9大隐式变量(在前面文章也叫预定义变量)在转化成为servlet后_jspService中可以看到: public void _jspService(final javax.servle ...
- 关于EL表达式中requestScope和param区别
今天演示EL表达式的时候发现自己jsp的基础实在是薄弱,在这个很简单的问题上迷惑了很久. 首先在看遇到的问题: 在浏览器地址输入,表示传入一个参数test,值为123 http://localhost ...
- 在jsp中怎么使用Cookie?el表达式中获取cookie的问题
初学jsp,不清楚cookie的使用方法,希望高手指点一下! 一般来说有两种办法,在JSP中使用Java的嵌入脚本. 例如: 写入Cookie <html> <head>. ...
- EL表达式中fn函数
JSTL 使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请求参数或者context以及 session中的数据的访问非常方便,但是我们在实际应用中经常需 ...
- 【JS-Java-EL】JavaScript和Java(EL表达式)引发的 Uncaught SyntaxError: Unexpected token ILLEGAL
2018.10.14 BUG原因: 在较早期的代码中,容易出现 JS 拼接 HTML 代码字符串的情况.如 // 页面 test.jsp 内部的 JS 代码 // ${} JSP中EL语法,内部为Ja ...
随机推荐
- [shell基础]——tr命令
(1) tr 字符替换 测试文本内容 # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. ...
- 收集的冻结table 标题和左侧(完美)
<html> <head> <meta name="viewport" content="width=device-width&q ...
- 【收藏】win7打开word每次提示配置解决办法
打开“我的电脑”——“ C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office Setup Controller ”——找到一个“ ...
- 如何将后台传来的json反序列化为前端具体对象
//jQuery方式 var obj = $.parseJSON(json); .... //eval var obj = eval("("+json+")" ...
- android 通过socket获取IP
如题<android 通过socket获取IP>: socket.getInetAddress().getHostAddress();
- Crtmp 源码分析
Crtmp Server接收rtmp音视频流,并实现音视频并发,可以作为直播后台的服务.整套代码量并不大,算是轻量级的服务. 花了些时间研究源码,现将研究的结果,记录下来,方便以后查阅. 先不从架构上 ...
- char a[] = "hello"; char c[] = {'h','e','l','l','o'}; int b[] = {1, 2, 3, 4, 5};的长度区别,及内存中空间开辟情况
1, char a[] = "hello"; char c[] = {'h','e','l','l','o'}; int b[] = {1, 2, 3, 4, 5}; 数组是开辟一 ...
- 重新认识Box Model、IFC、BFC和Collapsing margins
尊重原创,转载自: http://www.cnblogs.com/fsjohnhuang/p/5259121.html 肥子John^_^ 前言 盒子模型作为CSS基础中的基础,曾一度以为掌握了I ...
- poi实现Excel比较
http://stackoverflow.com/questions/866346/easiest-way-to-compare-two-excel-files-in-java http://stac ...
- Deep Learning: Assuming a deep neural network is properly regulated, can adding more layers actually make the performance degrade?
Deep Learning: Assuming a deep neural network is properly regulated, can adding more layers actually ...