相关疑难解决方法(0)

Java:d​​ouble vs float

在另一个Bruce Eckel练习中,我编写的代码采用了一种方法并在另一个类中更改了值.这是我的代码:

class Big {
  float b;
}

public class PassObject {
  static void f(Letter y) {
    y.c = 'z';
  } //end f()
  static void g(Big z) {
    z.b = 2.2;
  }

  public static void main(String[] args ) {
    Big t = new Big();
    t.b = 5.6;
    System.out.println("1: t.b : " + t.b);
    g(x);
    System.out.println("2: t.b: " + t.b);
  } //end main
}//end class
Run Code Online (Sandbox Code Playgroud)

它抛出的错误是"可能会损失精确度".

PassObject.java:13: possible loss of precision
found: double
required : float   z.b = 2.2
passobject.java:20: possible …
Run Code Online (Sandbox Code Playgroud)

java floating-point double types casting

22
推荐指数
4
解决办法
6万
查看次数

标签 统计

casting ×1

double ×1

floating-point ×1

java ×1

types ×1