cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with decimal

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you shouldn't use double.

Better use BigDecimal.

BTW where is difference in you two input values?

Regards

Patrick

Answers (1)

Answers (1)

Former Member
0 Kudos

thanks, ill take a look at that.

and sorry i meant 16.99 in the second example