我写了这段代码:
float b = 3.6;我明白了:
<上一页>错误:未解决的编译问题:类型不匹配:无法从 double 转换为 float为什么?float的定义是什么?
在 Java 中,当您键入一个十进制数为 3.6 时,它会被解释为一个 double.double 是 64 位精度的 IEEE 754 浮点,而 float 是 32 位精度的 IEEE 754 浮点.由于 float 不如 double 精确,因此无法隐式执行转换.
如果你想创建一个浮点数,你应该以 f 结束你的数字(即:3.6f).
更多解释请参见Java教程的原始数据类型定义.
I wrote this code:
float b = 3.6;
and I get this:
Error:Unresolved compilation problem:
Type mismatch: cannot convert from double to float
Why? Whats the definition of float?
In Java, when you type a decimal number as 3.6, its interpreted as a double. double is a 64-bit precision IEEE 754 floating point, while floatis a 32-bit precision IEEE 754 floating point. As a float is less precise than a double, the conversion cannot be performed implicitly.
If you want to create a float, you should end your number with f (i.e.: 3.6f).
For more explanation, see the primitive data types definition of the Java tutorial.
这篇关于Java中的浮点数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 JTextPane 中的组件周围环绕文本?How to wrap text around components in a JTextPane?(如何在 JTextPane 中的组件周围环绕文本?)
MyBatis,如何获取插入的自动生成密钥?[MySql]MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何获取插入的自动生成密钥?[MySql])
在 Java 中插入 Oracle 嵌套表Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java:如何将 CLOB 插入 oracle 数据库Java: How to insert CLOB into oracle database(Java:如何将 CLOB 插入 oracle 数据库)
为什么 Spring-data-jdbc 不保存我的 Car 对象?Why does Spring-data-jdbc not save my Car object?(为什么 Spring-data-jdbc 不保存我的 Car 对象?)
使用线程逐块处理文件Use threading to process file chunk by chunk(使用线程逐块处理文件)