简体   繁体   中英

How this implicit type conversion works in java?

Why the output of adding a double value with a float value in Java results in a double value which has more number of digits after decimal points than the input itself?

Why the digits after decimal points increased and who is supplying this additional value after the decimal points?

public class Main {
    public static void main(String[] args) 
    { 
        double data = 444.324; 
        float value = 5.1f; 
        System.out.println(value+data);   
    } 
}

Mathematically speaking the output should have been

449.424

right?

But the output of the following program is

449.4239999046326

Can anyone explain this behavior?

Noone is supplying the digits. You are just seeing rounding errors because floating point numbers cannot be accurately represented in computer memory.

Google floating point errors for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM