我是靠谱客的博主 激情魔镜,这篇文章主要介绍java 从double转换到float_关于浮点数:在Java中从double转换为float,现在分享给大家,希望可以做个参考。

如果我正在使用double,并将其转换为float,它如何工作? 值会被截断以适合浮点数吗? 还是舍入值不同? 抱歉,这听起来有点补救,但是我正在尝试掌握float和double转换的概念。

stackoverflow.com/a/2781125/986169

根据Java语言规范的第5.1.3节:

A narrowing primitive conversion from double to float is governed by the IEEE 754 rounding rules (§4.2.4). This conversion can lose precision, but also lose range, resulting in a float zero from a nonzero double and a float infinity from a finite double. A double NaN is converted to a float NaN and a double infinity is converted to the same-signed float infinity.

第4.2.4节说:

The Java programming language requires that floating-point arithmetic behave as if every floating-point operator rounded its floating-point result to the result precision. Inexact results must be rounded to the representable value nearest to the infinitely precise result; if the two nearest representable values are equally near,

最后

以上就是激情魔镜最近收集整理的关于java 从double转换到float_关于浮点数:在Java中从double转换为float的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部