java 取小数点后两位 不四舍五入,怎么做

正常版:
//正常版:
import java.text.DecimalFormat;
import java.math.RoundingMode; DecimalFormat formater = new DecimalFormat(); formater.setMaximumFractionDigits(2);
formater.setGroupingSize(0);
formater.setRoundingMode(RoundingMode.FLOOR); System.out.println(formater.format(123456.7897456));
简化版:(这个是四色五入,本人亲测.)
// 简化版:(这个是四色五入,本人亲测.)
import java.text.DecimalFormat; DecimalFormat formater = new DecimalFormat("#0.##");
System.out.println(formater.format(123456.7897456));

但是对于四色五入 , 我觉得用这个更好

// 简化版:(这个是四色五入,本人亲测.)
import java.text.DecimalFormat; DecimalFormat formater = new DecimalFormat("0.00");
System.out.println(formater.format(123456.7897456));

取自:  http://zhidao.baidu.com/link?url=Wd2GiFvfu_rGGqObUi2HSftJjQhZy9SmCNBr4jrXuezuTB8xk1stNin7JFIc8bIG2ELmaPEU7LGO_lt6SjwcZa

java 取小数点后两位 不四舍五入,怎么做的更多相关文章

  1. java取小数点后两位

    package com.yonyou.sud.algorithm; import java.math.BigDecimal;import java.text.DecimalFormat;/*** ja ...

  2. Java中取小数点后两位(四种方法)

    摘自http://irobot.iteye.com/blog/285537 Java中取小数点后两位(四种方法)   一 Long是长整型,怎么有小数,是double吧     java.text.D ...

  3. java 关于数字取小数点后两位出现整数0没有的问题

    最近再项目中对取到的一系列带很长小数的数字,展现时要求去小数点后两位显示就可以了 开始我是以下写法: double  a =  0.1234455; DecimalFormat decimalForm ...

  4. sql中对数值四舍五入取小数点后两位数字

    用:cast(value as decimal(10,2)) 来实现.

  5. Java数据处理,Map中数据转double并取小数点后两位

    BigDecimal order = (BigDecimal) map.get("finishrat"); double d = (order == null ? 0 : orde ...

  6. java截取小数点后两位

    String a = "123.3445776";int i = a.indexOf(".");System.out.println(a.substring(0 ...

  7. mysql格式化小数保留小数点后两位(小数点格式化)

    格式化浮点数的问题,用format(col,2)保留两位小数点,出现一个问题,例如下面的语句,后面我们给出解决方法 SELECT FORMAT(12562.6655,2); 结果:12,562.67 ...

  8. JAVA除法保留小数点后两位的两种方法 Java Math的 floor,round和ceil的总结

    floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...

  9. js除法四舍五入保留小数点后两位写法

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

随机推荐

  1. 关于css制作圆角

    三个阶段: 1.背景图片: 2.css2.0+标签模拟圆角: 3.css3.0圆角属性(border-radius). 1.1.背景图片--宽度固定,高度自适应圆角 为容器设置宽度 在主体的上方加一个 ...

  2. JMS - ExceptionListener

    If a JMS provider detects a problem with a connection, it will inform the connection’s ExceptionList ...

  3. .net System.Net.Mail 之用SmtpClient发送邮件 Demo

    private static bool sendMail() { try { //接收人邮箱 string SendTo = "XXXXX@163.com"; //抄送人邮箱 st ...

  4. Linux环境下Websphere重启

    一.Websphere控制台重启 1.更新class文件发布,Websphere自动重启. 2.更新web.xml发布,需要手动更新web.xml或者更新项目. web.config 缓存位置: We ...

  5. Cocos2d-x中播放背景音乐

    背景音乐的播放与停止实例代码如下: SimpleAudioEngine::getInstance()->playBackgroundMusic("sound/Jazz.mp3" ...

  6. (转)实战Memcached缓存系统(6)Memcached CAS的多线程程序实例

    1. 源程序 package com.sinosuperman.memcached; import java.io.IOException; import java.net.InetSocketAdd ...

  7. 【译】 Node.js v0.12的新特性 -- Cluster模式采用Round-Robin负载均衡

    原文:https://strongloop.com/strongblog/whats-new-in-node-js-v0-12-cluster-round-robin-load-balancing 本 ...

  8. spring读取prperties配置文件(2)

    接上篇,spring读取prperties配置文件(1),这一篇主要讲述spring如何用annotation的方式去读取自定义的配置文件. 这里我先定义好属性文件"user.propert ...

  9. 代码实现IMapcontrol当前视图输出为图片功能

    SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "保存输出图片"; dialog.Filter = &qu ...

  10. Windows内存原理与内存管理

    WIndows为每个进程分配了4GB的虚拟地址空间,让每个进程都认为自己拥有4GB的内存空间,4GB怎么来的? 32位 CPU可以取地址的空间为2的32次方,就是4GB(正如16位CPU有20根寻址线 ...