E
E
Eugene2019-09-19 07:02:03
Java
Eugene, 2019-09-19 07:02:03

Different output result for the same variable. What is the salt?

double x = 8.8;
        double y = 1.5;
        double z = x -y;
        System.out.printf("Result: %f", z);//Результат: 7,300000
        System.out.println(z); //Результат: 7.300000000000001
        float x1 = 8.8f;
        float y1 = 1.5f;
        float z1 = x1 - y1;
        System.out.printf("Result: %f", z1);//Результат: 7,300000
        System.out.println(z1); //Результат: 7.3

Faced with different output results of the same variable (z), why is this happening? My variant: in the first case, the float type is displayed, and in the second, the double type. Is it so?
Why is the integer part separated from the real part by a comma in the printf method, and a dot in the println method?
Why are z and z1 the same values ​​when using printf? They have different accuracy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-09-19
@sergey-gornostaev

https://0.30000000000000004.com/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question