zoukankan      html  css  js  c++  java
  • Java 浮点数精度问题 原理与解决方法

    原理:

    http://www.cnblogs.com/yewsky/articles/1864934.html

    工具类:

    http://www.cnblogs.com/szfei/archive/2012/01/30/2332151.html

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    简单方法:

    JAVA中控制double类型小数点后位数的方法

    有时候我们需要控制double类型小数点后的位数,下面简单介绍一下:

    假如现在想把某一个double的值限制在小数点后的4位,可以这样做:

    import java.text.DecimalFormat;  
      
    public class Main {  
        public static void main(String[] args) {  
                   DecimalFormat df = new DecimalFormat( "0.0000 ");  
                   double d1 = 1.0;  
                   double d2 = 4.56789;  
                   System.out.println(df.format(d1));   
                   System.out.println(df.format(d2));   
            }  

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    当当项目中的具体使用 

    节省:¥<%
               DecimalFormat df = new DecimalFormat( "0.00 "); 
                   Book book = (Book)request.getAttribute("book");
                   double d1 = book.getFixedPrice()-book.getDangPrice();

       
                   out.println(df.format(d1));   

        %>

  • 相关阅读:
    solr 的全量更新与增量更新
    solr 服务器的搭建
    Mysql 问题
    App 微信支付
    App 支付宝支付
    Linux 常见命令
    [备注] 钉钉使用教程
    PARAMETER和ARGUMENT的区别
    无界面浏览器
    URLs ...
  • 原文地址:https://www.cnblogs.com/LIS2011/p/2714660.html
Copyright © 2011-2022 走看看