Math.ceil and Math.floor returning same value

前端 未结 5 726
萌比男神i
萌比男神i 2020-12-31 00:31

I have a double (23.46)

And using the methods Math.ceil and Math.floor and parsing my double to these methods, I get the same value returned to me, which is 23...

5条回答
  •  清歌不尽
    2020-12-31 01:15

    How do you do the actual invocation? I cannot replicate your result, using either the double object or the primitive type.

    This code:

        Double d_object = new Double(23.46);
        double d_simple = 23.46;
    
        System.out.println("Ceiling simple: " + Math.ceil(d_simple));
        System.out.println("Floor simple: " + Math.floor(d_simple));
    
        System.out.println("Ceiling object: " + Math.ceil(d_object));
        System.out.println("Floor object: " + Math.floor(d_object));
    

    gives me:

    Ceiling simple: 24.0
    Floor simple: 23.0
    Ceiling object: 24.0
    Floor object: 23.0
    

提交回复
热议问题