Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why isn't there a Math.floor(float)?

Tags:

java

Why is there only Math.floor(double)?

I have a float and I want to round it "down".
do I have to cast it to double?

like image 640
Bick Avatar asked May 19 '11 15:05

Bick


People also ask

How do you get the float floor in Python?

In Python 2, floor(math. pi) returns a float value, whereas in Python 3, an int value is returned. In general, the Python 2 floor() function returns float values, whereas the Python 3 floor() function returns integer values.

What is math floor?

floor() The Math. floor() function always rounds down and returns the largest integer less than or equal to a given number.

What is math Floor 3.6 )?

The Math. floor() function in JavaScript is used to round off the number passed as parameter to its nearest integer in Downward direction of rounding i.g towards the lesser value. Hence, math. floor(3.6) = 3.


3 Answers

It will be converted automatically (see this on widening primitive conversions). If you want the result as a float, however, you will need to explicitly cast the return value.

like image 56
Oliver Charlesworth Avatar answered Oct 16 '22 10:10

Oliver Charlesworth


Yes, but when speed is critical support for single precision floats should be provided. There should be a single precision analogous for java.lang.Math

like image 9
Brendan K Avatar answered Oct 16 '22 11:10

Brendan K


No, a float primitive will automatically be cast to a double without the loss of any precision.

like image 3
Michael Avatar answered Oct 16 '22 11:10

Michael