相关疑难解决方法(0)

在Float中,为什么?

long b = 99;  
float c = 99.0F;  
//b = c; //Error : Cannot implicitly convert type 'float' to 'long'.
c = b; // Running Successfully.  Why?
Run Code Online (Sandbox Code Playgroud)

为什么数据类型的大小和隐式转换没有问题?我们知道
的大小float和long不同之处在下面给出...

Console.WriteLine("Long  : " + sizeof(long)); // Output --> Long : 8
Console.WriteLine("Float : " + sizeof(float));// Output --> Float: 4
Run Code Online (Sandbox Code Playgroud)

c# floating-point types

8
推荐指数
2
解决办法
7567
查看次数

Java允许将int隐式转换为float.为什么?

在Java中,我们可以隐式地将int转换为float,这可能导致精度损失,如下面的示例代码所示.

public class Test {
    public  static void main(String [] args) {
        int intVal = 2147483647;
        System.out.println("integer value is " + intVal);
        double doubleVal = intVal;
        System.out.println("double value is " + doubleVal);
        float floatVal = intVal;
        System.out.println("float value is " + floatVal);
        }
}
Run Code Online (Sandbox Code Playgroud)

输出是

integer value is 2147483647
double value is 2.147483647E9
float value is 2.14748365E9
Run Code Online (Sandbox Code Playgroud)

当精度损失时,允许将int隐式转换为float的原因是什么?

java

6
推荐指数
1
解决办法
5054
查看次数

标签 统计

c# ×1

floating-point ×1

java ×1

types ×1