Why is Math.ceil function malfunctioning in code coach section... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why is Math.ceil function malfunctioning in code coach section...

Java Math.ceil not working in code coach section.Why!!

24th Jul 2020, 3:41 PM
Aaron
Aaron - avatar
11 Answers
+ 1
Aaron Yes. It return double value. What result you need? Integer? Use type cast (int)Math.ceil(5.0/2); //3 answer.
24th Jul 2020, 4:07 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 but math.ceil returns a double ...
24th Jul 2020, 4:03 PM
Aaron
Aaron - avatar
+ 2
xᴏᴊɪᴀᴋʙᴀʀ Thanks..it's working
24th Jul 2020, 4:04 PM
Aaron
Aaron - avatar
+ 2
Jayakrishna🇮🇳 please refer a code...
24th Jul 2020, 4:04 PM
Aaron
Aaron - avatar
+ 1
xᴏᴊɪᴀᴋʙᴀʀ in Java it's Math.floor for nearest small... Math.ceil for nearest big number
24th Jul 2020, 3:54 PM
Aaron
Aaron - avatar
24th Jul 2020, 3:55 PM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
+ 1
Thanks Jayakrishna🇮🇳 ... Math.ceil requires double parameters
24th Jul 2020, 4:09 PM
Aaron
Aaron - avatar
+ 1
Aaron Just mathematics
24th Jul 2020, 4:10 PM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
0
Can we see the code or snippet?
24th Jul 2020, 3:46 PM
Jayakrishna 🇮🇳
0
Aaron 5/2 result 2 because both integers. If you want to get decimal point value, you need to have atleast one float or double value.. as 5.0/2 or 5/2.0 then you get 2.5 result, ceil(2.5) =3.0, you will get.... Hope it helps...
24th Jul 2020, 3:59 PM
Jayakrishna 🇮🇳