on 2022 Nov 05 2:02 PM
I have a requirement to convert a salary value: "100000" into "1,000.00". Salary is in double data type using Groovy. I am not sure on how to use it or to declare it. Can you guys help me? Thanks!
This is my code in the Groovy Script
<code>`import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.text.NumberFormat;
//Add Comma to Salary
//
def salaryFormat (double bnkAccount){
DecimalFormat df = new DecimalFormat("#,###.##");
double d = Double.parseDouble(input);
return d;
}
def Message processData(Message message) {
//creating the XML file/message
String str_body, email, a, d;
String [] str;
def body = message.getBody(java.lang.String);
def root = new XmlSlurper().parseText(body);
for(int i = 0; i<root.EmpJob.size(); i++)
{
str_body = "<root>"+'\n' + "<record>" +'\n';
str_body = str_body + "<Salary><![CDATA["+salaryFormat(root.EmpJob[i].User.salary.text())+"]]></Salary>"+'\n';
str_body = str_body + "</record>"+'\n';
str_body = str_body + "</root>"
}
message.setBody(str_body);
return message;
}`
And this is the error I am getting:
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script1__Script.groovy: 10: unable to resolve class java.util.text.NumberFormat @ line 10, column 1. import java.util.text.NumberFormat; ^ 1 error , cause: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script1__Script.groovy: 10: unable to resolve class java.util.text.NumberFormat @ line 10, column 1. import java.util.text.NumberFormat; ^ 1 error
User | Count |
---|---|
101 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.