从Integers的复合除法返回Double

时间:2015-11-19 01:42:04

标签: java division

我正在尝试从此double部门返回int。我读过this question但我似乎无法让它适用于这个特殊情况:

yComponent +=
        ((Math.min(i.getObservedIndividuals(), ii.getObservedIndividuals()))/
        Math.max(i.getObservedIndividuals(), ii.getObservedIndividuals())*
        i.getObservedIndividuals())/
        (parent.getShareableSpecies()*
        match.getTotalObservedIndividuals());

yComponentdouble,其他所有内容都是int

1 个答案:

答案 0 :(得分:1)

yComponent +=
    ((Math.min(i.getObservedIndividuals(), ii.getObservedIndividuals())) /
    (double) Math.max(i.getObservedIndividuals(), ii.getObservedIndividuals())*
    i.getObservedIndividuals()) /
    (double) (parent.getShareableSpecies()*
    match.getTotalObservedIndividuals());

如果不将至少一个操作数转换为double或float,则除法将不使用“浮点处理器”(算术处理器)。这意味着CPU为3 / 2 = 1,但3 / 2f = 1.5f