操作顺序,bigdecimal

rjzwgtxy  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(384)

当使用bigdecimal时,我得到了错误的期望值。我知道这与操作顺序和java读取它的方式有关,但我不知道如何纠正它。预期产量=5.1

length = 2.4
width = 1
effectivedepth = 1.5

Using brackets 
// (length * effectivedepth) + (width * effectivedepth) = Surfacearea50perDepth
 //(2.4 * 1.5) + (1 * 1.5) = 5.1
  surfacearea50perDepth = length.multiply(effectivedepth.add(width.multiply(effectivedepth)));

Output = 7.2

thanks in advance
qfe3c7zg

qfe3c7zg1#

求解,将有效深度置于支架外。。有效深度(宽度+长度)=sa

surfacearea50perDepth = effectivedepth.multiply(width.add(length));

相关问题