I wanna know why do java print me that number 9223372036854775807
when I write that statement System.out.print(Math.round(6.02e23)
. What exactly is java doing?
Math.round()
returns a long
. But your number overflows Long
's max value, which makes it return the maximum long
value possible: 9223372036854775807
From the JavaDoc:
If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
6.02e23 = 602000000000000000000000
Long.MAX_VALUE = 9223372036854775807
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With