cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to Calculate Price

Former Member
0 Kudos

Hi,

we have one UDF to calculate the price .The sample code for this UDF is ..

BigDecimal Value = new BigDecimal(Inputvalue);

If Curr = 'EUR' {

try {

while (true) {

Value = Value.setScale(Value.scale()-1);

}

} catch (ArithmeticException e) {

}

}

This UDF is working fine for all the value except multiples of 10.

For 10.00000 it's returning 1E +1

for 500.00000 it's returning 5E +2

Can someone help me to get correct values for multiples of 10 also.

Thanks,

Bharath.

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

> Value = Value.setScale(Value.scale()-1);

> This UDF is working fine for all the value except multiples of 10.

This is just what you have coded.

http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html

Answers (2)

Answers (2)

VijayKonam
Active Contributor
0 Kudos

> BigDecimal Value = new BigDecimal(Inputvalue);

> If Curr = 'EUR' {

> try {

> while (true) {

> Value = Value.setScale(Value.scale()-1);

> }

> } catch (ArithmeticException e) {

> }

> }

>

> This UDF is working fine for all the value except multiples of 10.

> For 10.00000 it's returning 1E +1

> for 500.00000 it's returning 5E +2

I see an infinite loop there for setting the scale..!! Was that intended? Every time you are decreasing the scale by one value. Instead why dont you call it once and set the scale to the number of digits you want after the decimal?

VJ

Former Member
0 Kudos

Hi Monish,

Please check my reply in this thread:

Regards,

---Satish

Former Member
0 Kudos

Satish,

Here I'm using BigDecimal,still it's failing for multiples of 10.

Thanks,

Monish

justin_santhanam
Active Contributor
0 Kudos

Monish,

When you say multiple of 10's not working, shall I consder - 23.00000 is working fine? 0 Just making sure on what criteria it's failing.

Thanks,

Justin.

Former Member
0 Kudos

Hello Raj,

23.000000 is working fine , we are having problem Only multiples of 10 , For Ex :

3500.000000 -- 3.5E+3

7500.000000 -- 7.5E+3

750.000000 -- 7.5E+2

10.000000 -- 1E +1

thanks,

Monish

vijay_kumar133
Active Participant
0 Kudos

Hi,

I used double for caluculations...

kindly update its double

so better use this , it will solve

Regards

Vijay

Edited by: vijay Kumar on Mar 17, 2010 5:05 PM