0

Consider this: a=Math.pow(b,c). Why can't I declare 'a' as integer? The program can run only when I change it to double.

26th Nov 2019, 11:35 AM
Addam
Addam - avatar
5 ответов
+ 4
That is because, Math.pow() function takes 2 arguments which are double and it also returns a double type value. Well why is that? Because if you try to do power of some number which has floating point value then int will not work.
26th Nov 2019, 11:51 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 4
Math.pow always returns a double, but you can explicitly cast it into an integer. int a = (int) Math.pow(2.0, 3.3); Of course you will lose all the decimals after the dot, if there were any, this is like floor rounding.
26th Nov 2019, 12:29 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Yes exactly Tibor Santa When you try to run without casting with an integer, Warning message we get is : it can be lossy conversation so they ask us to use double for it.
26th Nov 2019, 12:31 PM
Raj Chhatrala
Raj Chhatrala - avatar
0
Coding Panda Ouhhh now I get it. Thank you!
26th Nov 2019, 11:53 AM
Addam
Addam - avatar
0
I see
26th Nov 2019, 12:43 PM
Addam
Addam - avatar