zoukankan      html  css  js  c++  java
  • Java-小数点控制

    package 运算及类型转换类;  
      
    import java.text.DecimalFormat;  
      
    public class 控制小数点类 {  
         public static double decimalFormatD(int num, double d){  
                String format = "0.";  
                String result = "";  
                double db;  
                  
                for(int i=0;i<num;i++)  
                    format = format.concat("0");  
                  
                DecimalFormat decimal = new DecimalFormat(format);  
                result = decimal.format(d);  
                db = Double.parseDouble(result);  
                  
                return db;  
            }  
              
            public static float decimalFormatF(int num, float f){  
                String format = "0.";  
                String result = "";  
                float fl;  
                  
                for(int i=0;i<num;i++)  
                    format = format.concat("0");  
                  
                DecimalFormat decimal = new DecimalFormat(format);  
                result = decimal.format(f);  
                fl = Float.parseFloat(result);  
                  
                return fl;  
            }  
      
              
            public static String doubleToString(double f){         
                String s = "";  
                double a = 0;  
                  
                while(f >= 1) {  
                      
                    a = f%((double)10);  
                      
                    s = String.valueOf((int)a) + s;  
                    f=(f - a)/10;  
                }  
                return s;  
            }  
    }  
  • 相关阅读:
    javascript类继承系列一
    Update Statistics用法
    FOR XML PATH
    SQL Server 中WITH (NOLOCK)
    ROW_NUMBER () 与 PARTITION组合拳
    sql脚本的格式
    存储过程
    动态sql
    尽量不要用select into 复制表
    杂谈
  • 原文地址:https://www.cnblogs.com/hwaggLee/p/4510659.html
Copyright © 2011-2022 走看看