Java 中 Number 对象的模

发布于 2024-12-15 00:25:17 字数 76 浏览 2 评论 0原文

有没有安全的方法可以在 Java 中对 Number 类型的对象应用模函数?

尝试采用“数字通用”方式来对集合应用过滤器。

Are there any safe ways to apply the modulus-function on objects of type Number in Java?

Trying to make a "Number-generic" way to apply a filter on a collection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2024-12-22 00:25:17

唯一的通用方法将涉及仅使用抽象 Number 类中定义的方法,因此,如果您所说的“安全”是指不丢失精度,那么就不会,因为 Number 中定义的所有方法 警告它们可能会舍入或截断结果(floatValue()doubleValue() 除外,它们仅舍入)。

The only generic approach would involve working only with methods defined in the abstract Number class, so if by "safe" you mean without losing precision, then no, because all of the methods defined in Number warn that they may round or truncate the result (except for floatValue() and doubleValue(), which only round).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文