cancel
Showing results for 
Search instead for 
Did you mean: 

Round Off Currency Field to 2 Digits

Former Member
0 Kudos

Hi Friends,

I have field called Amount which is coming form R/3 system into XI... This field will have 4 decimal points..but In XI message mapping i want to round it off to 2 decimal points....I tried with Format Number, but it is giving error when i pass negative numbers...The reason is that From R/3 System the negative numbers are coming like " 1234.4356- " ..The negative sign is coming at the end of the number...I don't want to change this format but want to round off the decimal point ot 2 degits...

Regards,

Shyam M.

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Shyam,

Use the below logic.

Create Simple UDF - Let's consider input argument name is value


     String app="";
     if(value.length()>7)
     {
     app ="-";
     }
     
     BigDecimal test = new BigDecimal(value.substring(0,7));
     
     test = test.setScale(2,BigDecimal.ROUND_HALF_UP);
     
      String ret = ""+test+""+app;
return ""+ret+"";

Hope it helps!

raj.

Edited by: Raj on Mar 17, 2008 12:20 PM

Former Member
0 Kudos

Hi Shyam,

I tried this

Number + constant(-) --> endWith --> if then else (boolean)

If it ends with - (negative) then

number --> substring (0..7) + constant --> concat --> then

else

number > FormatNumber(#.00)> else

It is working fine.

Thanks,

Srini

Edited by: srinivas kapu on Mar 17, 2008 12:32 PM

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

only with FormatNum is not possible, because the value with a negative sign at the end will be interpreted as a string and not as a number.

But you can do it with the following standard functions:

if (Boolean)

endsWith (Text)

FormatNum (Arithmetic)

replaceString (Text)

concat (Text)

constant (Constant)

if

sourceValue endsWith(constant("-"))

then

replaceString(sourceValue, Constant("-"), Constant("0")) the result from replaceString goes into FormatNum(#,00)

concat (result from FormatNum, Constant("-"))

else

formatNum(#.00)

Regards

Patrick

Edited by: Patrick Koehnen on Mar 17, 2008 6:14 PM

Former Member
0 Kudos

HI,

You can use the formatNumber Function where after the decimal you can specify two digits and it would round it off.But in your case since you are saying that the negative sign comes than u can follow the following approach:

You can write a UDF where it accepts the input and a checks if the input ends with a negative sign.If it ends than just substring it and than use the round function and later concat the "-" sign to the output of the Round function.

Let me know if u need furthur information.

Thanks,

Bhargav.

Note:Award points if found useful

Former Member
0 Kudos

Hi Bhargav,

Is there any way to do this using standard functions itself....May be playing with format number or any other standard functions...... Is it not possible using format number alone???