cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to Sum sign Numbers

Former Member
0 Kudos

Hi,

We are looking for a UDF to sum sign numbers.

Example,

String[] Amount={"00000000013.20","000000000017.56","00000000013.20-","000000000017.56-"};

Output = 13.20 + 17.56 - 13.20 - 17.56.

Any help is appreciated.

-santosh.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi, try out the standard function sum that calculates the Sum of values X1 to Xi of a context. You find it in the Function Category: Statistics.

Former Member
0 Kudos

Hi,

here's the code,

you have to adapt it to work a bit on pi.



public static String sum(String[] amount){
		double res=0;
		for (int i=0;i<amount.length;i++){
			String local = amount<i>;
			if (local.contains("-"))
				res-=Double.parseDouble(local.replace("-",""));
			else 
				res+=Double.parseDouble(local.replace("+",""));
		}
		
		return Double.toString(res);
	}

Former Member
0 Kudos

Hi ciochina/martin,

Thanks for the code.