当参数为整数[重复]时,双值会变为最低值

问题描述 投票:-1回答:1

这个问题在这里已有答案:

如果我有{“myparam”:12.8}并且我的请求类有 整数myparam; myparam设置为12而不是13。 为什么它是一个楼层而不是四舍五入?

java truncate
1个回答
1
投票

这是从Double请求int值的预期行为(如Double API中所示):

public abstract int intValue()
Returns the value of the specified number as an int. This may involve
rounding or truncation.
Returns:
the numeric value represented by this object after conversion to type int.

解释它的最简单方法 - 从double获取int时,包括'。'在内的所有权利。被切碎了。

© www.soinside.com 2019 - 2024. All rights reserved.