on 03-17-2008 4:36 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.