大家好!我想请教一个问题!现在有 float f=123.9999;我想要去掉小数点后的9999,得到'123'。不要四舍五入的。请问怎样实现? 谢谢! 在线等着!!

解决方案 »

  1.   

    public class Test {
        
        public static void main(String arg[]){
            float f = 123.9999f;
            String f1 = String.valueOf(f).substring(0,3);
            System.out.println(f1);
            float f2 = Float.parseFloat(f1);
        }}
      

  2.   

    float f=123.9999f;
    String s=Float.toString(f);
    s=s.substring(0, s.indexOf('.'));
    System.out.println(s);
      

  3.   

    int a = new Float(123.9999).intValue();
      

  4.   

    to:chenggm(我是菜菜)
    要是
    float f = 123465.9999f;
    你怎么办?
      

  5.   

    float f=123.9999;
    long a = Math.round(f - 0.5);
    a就是你要的结果
      

  6.   

    infon(阿槑) 的方法好用 谢谢你!