Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Long conversion double problem of java
Long conversion double problem of java
Long is a basic variable type with higher precision than double. If you convert it forcibly here, it will cause the problem of insufficient precision.

This is the result of running your code. Can you see that it is not accurate enough?

Long is a long integer variable, and double is a double-precision floating-point number (actually a decimal).

Then here b/ 1000 is equal to 12, because b is long, his calculation result will also be long.

Therefore, it is necessary to forcibly replace b with double type before calculation, so as to ensure that the accuracy is not missed.