2147483648.0实际上是231,而int的最大值是231-1.那么这个浮点值就是一个值太高的值.

In the first step, the floating-point number is converted either to a long, if T is long, or to an int, if T is byte, short, char, or

int, as follows:

If the floating-point number is NaN (§4.2.3), the result of the first step of the conversion is an int or long 0.

Otherwise, if the floating-point number is not an infinity, the floating-point value is rounded to an integer value V, rounding

toward zero using IEEE 754 round-toward-zero mode (§4.2.3). Then

there are two cases:

If T is long, and this integer value can be represented as a long, then the result of the first step is the long value V.

Otherwise, if this integer value can be represented as an int, then the result of the first step is the int value V.

这里的相关部分是值将向零.只要浮点值(或长)高于Integer.MAX_VALUE,则转换为int将导致其最高值.对于低于Integer.MIN_VALUE的值也是如此.

如果你使用(int)-214783649L;它会突然变成214783647!为什么这种情况也在JLS中解释,重点是我的:

A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, where n is the number of bits used to represent type T. In addition to a possible loss of information about the magnitude of the numeric value, this may cause the sign of the resulting value to differ from the sign of the input value.

该值在二进制中的长时间表示,表示32位截止值,如下所示:

1111 1111 1111 1111 1111 1111 1111 1111 | 0111 1111 1111 1111 1111 1111 1111 1111

当转换发生时,前32位被丢弃,留下最高可能的int.

反向是正的长 – 高32位包含所有1在转换时被丢弃.

完整结构如下,管道再次表示32位标记:

1111 1111 1111 1111 1111 1111 1111 1111 | 1000 0000 0000 0000 0000 0000 0000 0000

java类型转换 float类型转换_Java类型转换 – float(和long)到int相关推荐

  1. java强转规则_java类型转换及其规则介绍

    一.自动类型转换 整型.实型(常量).字符型数据可以混合运算.运算中,不同类型的数据先转化为同一类型,然后进行运算. 数据类型转换必须满足如下规则: 1.不能对boolean类型进行类型转换. 2.不 ...

  2. java char short区别_java 彻底理解 byte char short int float long double

    遇到过很多关于 数值类型范围的问题了,在这做一个总结,我们可以从多方面理解不同数值类型的所能表示的数值范围 在这里我们只谈论 java中的数值类型 首先说byte: 这段是摘自jdk中 Byte.ja ...

  3. java float是_java中float是什么意思

    Java中float的意思"浮动",代表的是一种浮点数数据类型,它内存分配4个字节,占32位,范围从"10^-38"到"10^38"和&qu ...

  4. java double数值范围_Java中float和double的取值范围该怎样理解?

    展开全部 基本类型float占4个字节,二进制位数e5a48de588b662616964757a686964616f31333366306464有32位,取值范围为[-3.4028234663852 ...

  5. java字符如何向float转换_java – 将float转换为字符串分数表示

    最简单的方法可能是使用反复试验. public static String toFraction(double d, int factor) { StringBuilder sb = new Stri ...

  6. java类型转换_JAVA类型转换大全

    Java自带的库很多用起来都不是那么方便,类型转换很多都要显示去做真的有点难记住.找了篇资料说的很详细,记录下来吧. integer   to   String   :         int   i ...

  7. java中类型转换的造型_Java总结篇系列:类型转换/造型

    Java中,经常可以遇到类型转换的场景,从变量的定义到复制.数值变量的计算到方法的参数传递.基类与派生类间的造型等,随处可见类型转换的身影.Java中的类型转换在Java编码中具有重要的作用. 首先, ...

  8. java强制转换用法_Java入门课|这才是Java强制类型转换的正确使用方法,你真的会用这些吗...

    [摘要]作为一门面向对象编程语言,Java吸收了C++语言的优点,也展现了其强大的一面,我们能在各个地方看到其功能强大和简单易用的两个特征,当然,也吸引了很多程序员的注意力,所以就有人想了解Java的 ...

  9. java变量的类型转换基本知识_Java基础知识(一):注释、关键字、标识符、数据类型、常量、变量、数据类型转换...

    1.java中注释有三种形式 单行注释:// 多行注释:/**/ 文档注释:/**      */ 2.java中的关键词(不需要记忆) 关键词的特点:均由小写字母组成,代码编辑器会给颜色提示 3.标 ...

  10. java变换变量赋值_Java变量的类型转换

    在程序中,当把一种数据类型的值赋给另一种数据类型的变量时,需要进行数据类型转换.根据转换方式的不同,数据类型转换可分为两种:自动类型转换和强制类型转换.自动类型转换 自动类型转换也叫隐式类型转换,指的 ...

最新文章

  1. react-antd项目中重新npm  install  导致自动升级antd版本,引发的样式问题
  2. html的body内标签之图片及表格
  3. halcon知识:工业相机问答(更新中...)
  4. 常见的前端vue面试题
  5. boost::sort模块实现spreadsort 双排序示例
  6. typescript类型断言
  7. Latex设置字体大小
  8. mysql查询男生基本情况_MySQL数据库技术与应用:数据查询
  9. OpenCV_08 边缘检测:Sobel检测算子+Laplacian算子+Canny边缘检测
  10. python类的私有属性_Python类的私有属性
  11. 15个常用的javaScript正则表达式
  12. 自动驾驶的Pipline -- 如何打造自动驾驶的数据闭环?(上)
  13. 自动获取服务器,c#-自动获取服务器IP到客户端
  14. php mysql登陆页面完整代码_PHP实现用户登录的案例代码
  15. wwwscan目录扫描器的逆向分析
  16. 必备浏览器插件,不用安装音乐软件全家桶,轻松下载全网音乐!
  17. js代码实现点击按钮出现60秒倒计时
  18. java实现华氏温度和摄氏温度互相转换
  19. 实现PPT演示的"非全屏播放"效果
  20. 刷题汇总(一)leetcode 精选50题 JavaScript答案总结

热门文章

  1. vscode 离线安装python插件_vscode for Python插件下载-Visual Studio Code Python插件下载0.9.1 官方版-西西软件下载...
  2. python输出一首诗_Python里隐藏的 诗
  3. Android:eclipse安装adt插件后工具栏不显示android相关图标
  4. composer切换源_composer的安装 及 常用命令(切换源等)
  5. 可重构麦轮全向移动机器人分析(图片版)
  6. mysql 权限管理无效_mysql 权限控制笔记
  7. 树莓派python安装xlwt_利用python包(xlrd和xlwt)处理excel
  8. python通过什么对象连接数据库_干货!python与MySQL数据库的交互实战
  9. 背景半透明(HTML、CSS)
  10. Exchange Server 2016管理系列课件03.管理邮箱配额限制