# Problem with decimal

Hi experts,

i designed a simple UDF that sums all the value of a segment.

The problem is that in my output I tend to get like 10 decimals!!

Is that normal ? How can I manage to get the value I want??

For example, in my segments I have the following values:

21.00, 15.00, 16.90

as result I get 52.9 which is OK

but when I have 21.00, 15.00, 16.90

the result I get is

52.989999999999995 !!??

How come?my code is the following:

public static void add_all_zvalnet(String[] ZVALNET,ResultList result,Container container){ double sum = 0; for (int i = 0; i < ZVALNET.length; i++){ sum = sum + Double.parseDouble(ZVALNET<i>); } result.addValue(""+sum); }

thx for your help

kind regards,

Jamal

##### Patrick Koehnen replied

Hi,

you shouldn't use double.

Better use BigDecimal.

New Arithmetic and Statistical Functions in Message Mappings in SP18

BTW where is difference in you two input values?

Regards

Patrick