如何在java上获得与php相同的结果?

Why on php this printf((2376995291 - 141 * 16777216) / 65535) on

result 174.0724040589.

On Java System.out.println((2376995291L - 141 * 16777216) / 65535)

result 65711 .

Why its two different result and how get result PHP on Java , i need get 174 on java.

System.out.println((2376995291L - 141L * 16777216L) / (double)65535);

141 * 16777216 will technically overflow since it's greater than 2^31 - 1. So, make them as long numbers to avoid overflow and you could typecast the denominator if you like to get the result with decimal points as well.

You need to cast the number to float or Java will simply ignore the decimal places.

System.out.println(((float) (2376995291L - 141L * 16777216L)) / 65535f)

Because multiplication of is long number.Need to define it as long

Splited into 2 step for just clarification.

    public static void main(String[] args) {
            Long te = (141L * 16777216L);
            System.out.println((2376995291L - te) / 65535);

        }

141 * 16777216 is too big for an int. If you do that part of the calculation as a long, you'll get the right answer.

jshell> (2376995291L - 141 * 16777216L) / 65535
==> 174

In java Try this

System.out.println((2376995291L - 141 * 16777216L) / 65535L);