cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for BigDecimal Sum

Former Member
0 Kudos

Hi All,

I have to sum all of my amount values in Detail Records. I want to use BigDecimal in UDF because if I use the standard sum, the precision is going to be more than 4 digits. So if we use BigDecimal then I will get the exact result. Can anyone please help me for writing the UDF for getting the sum of all my numbers using BigDecimal.

Your inputs are highly appreciated.

Cheers,

korobee

Accepted Solutions (0)

Answers (2)

Answers (2)

santhosh_kumarv
Active Contributor
0 Kudos

Hi,

Refer this Blog <a href="/people/thorsten.nordholmsbirk/blog/2006/08/25/new-arithmetic-and-statistical-functions-in-message-mappings-in-sp18 Arithmetic and Statistical Functions in Message Mappings in SP18</a>.

Following is the code to add two numbers using BigDecimal.

String add(String a, String b)
{
  BigDecimal bigA = new BigDecimal(a);
  BigDecimal bigB = new BigDecimal(b);
  BigDecimal bigSum = bigA.add(bigB);
  return bigSum.toString();
}
Refer: Blog 

Thanks,

SaNv...

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

There is a statistic function called sum. You may need to use format number.Can you please provide a sample input/output?

Hope this helps,

Regards,

Edited by: Mark Dihiansan on Mar 16, 2009 3:46 PM