为什么24 * 60 * 60 * 1000 * 1000除以24 * 60 * 60 * 1000在Java中不等于1000? [英] why is 24 * 60 * 60 * 1000 * 1000 divided by 24 * 60 * 60 * 1000 not equal to 1000 in Java?

查看:404
本文介绍了为什么24 * 60 * 60 * 1000 * 1000除以24 * 60 * 60 * 1000在Java中不等于1000?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么24 * 60 * 60 * 1000 * 1000除以24 * 60 * 60 * 1000在Java中不等于1000?

why is 24 * 60 * 60 * 1000 * 1000 divided by 24 * 60 * 60 * 1000 not equal to 1000 in Java?

推荐答案

因为乘法溢出32位整数。在64位中它没关系:

Because the multiplication overflows 32 bit integers. In 64 bits it's okay:

public class Test
{
    public static void main(String[] args)
    {
        int intProduct = 24 * 60 * 60 * 1000 * 1000;
        long longProduct = 24L * 60 * 60 * 1000 * 1000;
        System.out.println(intProduct); // Prints 500654080
        System.out.println(longProduct); // Prints 86400000000
   }
}

显然在乘法溢出后,分裂不会撤消溢出。

Obviously after the multiplication has overflowed, the division isn't going to "undo" that overflow.

这篇关于为什么24 * 60 * 60 * 1000 * 1000除以24 * 60 * 60 * 1000在Java中不等于1000?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆