如何正确输出正确的double值?

时间:2014-03-09 19:11:17

标签: java primitive-types

所以我试图增强这些类型以获得输出d = 5.5,我尝试了不同的类型,我得到的是5.0,我该怎么做才能获得正确的输出?

    int a = 5;
    int b = 4;
    int c = 3;
    int e = 2;
    double d = (double)(a) + b/c/e;
    System.out.println(d);

3 个答案:

答案 0 :(得分:1)

double d = a + (double)(e / b);

答案 1 :(得分:1)

double a = 5.0;
double b = 4.0;
double c = 4.0;
double  e = 2.0;
double d = a + b/c/e;
System.out.println(d);

这将给出5.5:)

答案 2 :(得分:1)

这就是你要找的东西吗?:

double d = (double)(a) + ((double)(b/c))/(e);