为什么C#Math.Floor()返回双,而不是Int的 [英] Why does C# Math.Floor() return Double instead of Int

查看:705
本文介绍了为什么C#Math.Floor()返回双,而不是Int的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
为什么Math.Floor(双人间)返回double类型的值?

为什么C# Math.Floor()收益双击而不是 INT

Why does C# Math.Floor() return double instead of int

从MSDN文档:

返回最大的整数小于或等于指定的双精度浮点数

Returns the largest integer less than or equal to the specified double-precision floating-point number

它说,它返回一个整数。其确定返回双击,我可以随时将其转换为 INT 但它只是很奇怪,是不是它?

it says it returns an integer. Its ok to return a double, I can always cast it to an int but its just quite strange, isn't it?

推荐答案

不是真的,考虑到双击可以高得多大小比 INT 。你不会想溢出与大值双可能是一个int

Not really, considering that a double can be a much higher magnitude than an int. You wouldn't want to overflow an int with the large value that a double could be.

只是为了显示你我的意思:

Just to show you what I mean:

Double.MaxValue = 1.7976931348623157E + 308

Double.MaxValue = 1.7976931348623157E+308

Integer.MaxValue = 2,147,483,647

Integer.MaxValue = 2,147,483,647

所以,你可以有双重即3,000,000,000.50和地板它,这会溢出int的最大值。

So you could have a double that is 3,000,000,000.50 and floor it, which would overflow the max value of an int.

这篇关于为什么C#Math.Floor()返回双,而不是Int的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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