+ 3
how math.floor() works in java?
give few examples of math.floor() ... in java.
2 Antworten
+ 11
● How to use it ? (Sample code) :
double x=1.5,y=-1.5;
System.out.print(Math.floor(x)+" "+Math.floor(y));
//1.0 -2.0
● How it works ?
It works like Greatest Integer Function( gif),
For example:
○ gif(N) = N //if N is an integer.
○ gif(N) = A //if N is an number between two closest integers A & B, we took the integer of lower value.
● it returns double value
+ 3
floor(12.999) == 12
floor(345.34) == 345
It just rounds down.