on 09-15-2015 10:39 AM
Hello Experts,
I have a requirement where i have have to format a number like below way..
If Source value is 34300 then target value would be 343.0
if 100 then -- target Val = 1.0
If 50000 then --- target Val = 5.0
Please help me with a UDF
Regards,
Joseph
Hi Maverick,
From my understanding your requirement is removing the suffix zeroes in the input and adding suffix .0 to the modified input.
Please try the below udf and check the outcome.
Code snippet:
int i = input.indexOf('0');
String result="";
if(i>0)
result = input.substring(0,i) + ".0";
else
result = input + ".0";
return result;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vishnu,
Just a correction hope you dont mind
in case the number is 234045000
int i = input.indexOf('0'); would give 3 i hope you want 6 for this number as the index of 0
A correct approach might be
int num = Integer.parseInt(field[0]);
int count =0;
while(num%10 ==0)
{
num = num/10;
count++;
}
result.addValue(field[0].substring(0,field[0].length()-count)+".0");
//regex for ending zeroes can be used alternatively with replaceAll method of string ([0]+\b)
Hi Joseph,
The logic is not for format number. You are dividing the no and then formatting with decimal. first you need to identify the logic to divide the no (100, 1000 etc.) then use format no to format it with decimal.
regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
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.