cancel
Showing results for 
Search instead for 
Did you mean: 

Source value 12.1 has to be converted to 12.10

Former Member
0 Kudos

Hi all,

My requirement is, if we get a source value with 12.1 we need to convert this to 12.10.

If i get 0 from source i need to get 0 as output.

so basically i need to find out of decimat dot (.) exists or not and if itdoesnot exists then pas the value as it is.

if decimal exists then check of the lenght is 2 after decimal, its 2 send the value as it is...if its 1 then append 0 and pass the value.

How do i achieve it using UDF or Graphical mapping.

Thanks & Regards,

Karthick

Edited by: karthick Lakkaraju on Mar 3, 2010 7:29 PM

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Karthick,

You can do like this for your logic. First lets find whether you have a decimal in input. If no then pass as it is. If yes then we will use two udfs one for getting the value before decimal and one after getting the value after decimal. Once we get the value after decimal lets check the length and if it is more than two then substring the input. Else we will multiply by 10 which will give you the resulted value. After this we will concat both the before decimal value and afte decimal value.

Map as shown in this picture:

http://gickr.com/results4/anim_a2beb86b-c332-1f14-5981-09a5c0011208.gif

The code for the two udfs are:

udf1: Create a value udf with one input arguemnt a and name it as beforedecimal. Then add this code:

Imports: java.*;

int i = a.indexOf(".");

a = a.substring(0,i);

return(a);

udf2: Create a value udf with one input arguemnt a and name it as afterdecimalvalue. Then add this code:

Imports: java.*;

int k = a.length();

int i = a.indexOf(".");

i = i +1;

a = a.substring(i,k);

return(a);

Then you should get as expected. I tested withall the test cases you mentioned and it works fine for me.

Regards,

---Satish

stefan_grube
Active Contributor
0 Kudos

why so complicated?

with eqalsA check if zero,

use if

then branch: put constat "0"

else branch: put source - formatNumber with property as ######0.00

former_member200962
Active Contributor
0 Kudos

Source --> UDF --> Target

UDF code will be:

int len = value.lastIndexOf("."); //to check position of decimal value

value = value.substring(len+1);

if (value.length() < 2){

value = value + "0";

return value;

}

The above UDF code may require some modification!

former_member181962
Active Contributor
0 Kudos

do as follows

1) Use the IndexOf function in string functions to check the occurance of a .(dot) in the input field)

2) If the indexOf returns a value greater than 0, then use formatNumber function with property as #######.##

3) In the else condition, pass the input value directly.

Regards,

Ravi

Former Member
0 Kudos

Hi Ravi,

In that case if i pass 12.1033 the output after farmatnumber would be 12.1.

But i would like to see 12.10.

Cheers,

Karthick

former_member208856
Active Contributor
0 Kudos

give format like

in FormatNumber

Number format 00000.00 (give 2 decimal places in format).

Decimal place "." (Give value of decimal)

former_member200962
Active Contributor
0 Kudos

you changed the req:(