Apache Pig浮点数SUM精度错误

时间:2016-03-11 13:18:26

标签: sum double apache-pig floating

我有双值的行。 然而,它们的总和有额外的浮动数字,我不想在输出中。有什么想法可以避免这个问题?

A = LOAD 'test.csv' Using PigStorage(',') AS (
        ID: chararray,
        COST:double
);
B = GROUP A BY (ID);
C = FOREACH B GENERATE SUM(A.COST); 
STORE C INTO 'out.txt' USING PigStorage(',');

INPUT FILE

A,0.51
A,0.51
B,4.81
B,4.81

预期输出文件

A,1.02
B,9.62

ACTUAL INVALID OUTPUT FILE

10.020000457763672
9.619999885559082   

1 个答案:

答案 0 :(得分:1)

尝试C = FOREACH B GENERATE ROUND(SUM(A.COST)*100.0)/100.0;

修改  它有效,见输出

enter image description here