on 08-27-2008 5:14 PM
Hi experts,
Can someone let me know whether there is a chance to fulfill the below requirement:
Input file:
In the Input CSV file, there is a fixed length field with length 9 char and has leading zeroes (ex: 000000650)
Output file:
In the O/p XML file, the corresponding value should be displayed as "6.50" (Have to remove the leading zeroes, right justified and the last two digits should be allocated for decimals)
Can anyone let me know if we can handle in Message mapping or should we write a UDF? If so can you please provide the code..
Any help would be highly appreciated !!
Thnx
- Ravi
The code in UDF.. a is input parameter..
String str1 = a;
String str2 = null;
String str3 = null;
str1 = str1.replaceFirst("0*",""); // replacing leading zeros with nothing
str2 = str1.substring(str1.length()-2); // taking out last 2 for decimal places
str3 = str1.substring(0,(str1.length()-2)); // taking rest of the string
return str3 + "." + str2;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Check with this UDF
public String change(String a,Container container)
{
//write your code here
if(a.length() > 0)
{
String b = a.replaceAll("^0*","");
float c = Float.parseFloat(b);
float d = c/100;
String e = Float.toString(d);
return e;
}
else
{
return a;
}
}
src->udf->target
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No need of UDF..
Use this mapping format http://www.flickr.com/photos/28929439@N06/2805931373/
Thanks
SaNv...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravi,
UDF:
Create a function zerosuppress and take the cache as value and take one argument input. Then put the code below:
//Put this code
String output = input.replaceFirst("^0+","");
return output;
With this function your leading zeros will remove.
Then map like this:
source field --> zerosuppress (udf) --> divide by 100 --> target field.
This should solve your issue.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry wrong input
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This can be easy done using graphical mapping no need to use UDF .Use Trim Function to trim the leading zero's then split the number then concat with a . using a constant.
Hope this helps.
Thanks,
Karthik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Delete the left side 0's.
while(input.startsWith("0"))
{
String y=input.replaceFirst("0","");
}
return y;
You can divide that number by 100.
or
Import this package : java.text.NumberFormat;
NumberFormat testNumberFormat = NumberFormat.getNumberInstance();
testNumberFormat.setMinimumFractionDigits( 2 );
// Here you can set the numbers, suppose you want the output like 123.589 then set here 3.
testNumberFormat.setMaximumFractionDigits( 2 );
String val1=testNumberFormat.format(input_field_name);
return val1;
try FormatNum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.