Skip to main content

I have authored a workspace that creates bills for a lot of customers. The item price on the bill has to be returned with 2 decimals, so I take the mean of all the item prices and ceil the number to 2 decimals. Because of an occasional outlier I can't rely on normal rounding function.

In the case below I have 1.173 measurements with an item price of 0,43. The min and max is 0,43 and the range is 0. But the mean value is != 0,43. And since I have to use the ceil function the price changes to 0,44.

I understand this must be caused by the internal handling of 32 to 64 bit conversion, but in this case a seemingly very simple operations doesn't work.

Why can't I rely on the mean calculation?

What can I do to rely on it in the future?

 

Statistics calculator

Why do you have to use @Ceil? @Round seems to be a more logical choice, and it gives 0,43 as a result.


Why do you have to use @Ceil? @Round seems to be a more logical choice, and it gives 0,43 as a result.

Because of an occasional outlier I can't rely on normal @Round function. The client has a say in this as well, guess they wanna have all rounding to their advantage. And it shouldn't cause any problems if mean is calculated correctly.


Why do you have to use @Ceil? @Round seems to be a more logical choice, and it gives 0,43 as a result.

But the mean is calculated correctly. 

The difference you get is a result of the inaccuracy of calculating with decimal numbers. So you should @round to a lower number of decimals decimals before applying @ceil, something like:

@ceil(@round(@Value(TheMeanValue),6),2)

 


But the mean is calculated correctly. 

The difference you get is a result of the inaccuracy of calculating with decimal numbers. So you should @round to a lower number of decimals decimals before applying @ceil, something like:

@ceil(@round(@Value(TheMeanValue),6),2)

 

That's what I did as a workaround - but it feels pretty unsatisfying.

And mathematically it is wrong. That can't be discussed. It is calculated correctly only within the bounds of floating point approximations, but that doesn't make it right, it just makes it the best representation. So in this case FME shouldn't perform a calculation at all, it should just transfer the value.


But the mean is calculated correctly. 

The difference you get is a result of the inaccuracy of calculating with decimal numbers. So you should @round to a lower number of decimals decimals before applying @ceil, something like:

@ceil(@round(@Value(TheMeanValue),6),2)

 

I don't think FME 'knows' all values are identical. FME simply calculates the mean value from the sum of all values, and the number of values.

But I agree that, when the minumum value equals the maximum value, FME could be instructed to just return that value. 

Maybe you can submit an idea for this. It would help other users who encounter this behaviour.


Reply