cancel
Showing results for 
Search instead for 
Did you mean: 

Round Number in Mapping

Former Member
0 Kudos

Hi All,

I need some help in mapping.

I have a input number which i need to round off based on the total length.

Source Value:

Source1 = 123.123456789

Source2 = 12345.12345678

Answer :

Target1 = 123.12346

Target2 = 12345.12346

So if you see the Targetx length should always be within 10.(5 digits before decimal & 5 after decimal)

Can we achieve the above using standard functions? If not maybe some help on how to?

Thanks.

Rahul

Edited by: Rahul Jain on Dec 22, 2009 8:21 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can do this by simply writing a UDF as given below;

NumberFormat formatter = new DecimalFormat("00000.00000");
    			String Target  = formatter.format(Source);

Note: Include class "java.text.NumberFormat;java.util.Arrays;java.text.DecimalFormat;" into imports section of UDF

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Just use the std function FormatNum. In the properties of formatnum function give #####.##### as Number Format and under Decimal Separatero just put the decimal point.

Not need to multiply or divide by 10000. The function will automatically round off the values for you.

Regards,

Sarvesh

Former Member
0 Kudos

Hi,

you could use the standard function: Arithmetic -> FormatNumber (00000.00000)

Sarvesh is right -> FormatNumber round if necessary

Regards

Patrick

Edited by: Patrick Koehnen on Dec 22, 2009 10:57 AM

Former Member
0 Kudos

Rahul,

I hope if there are digits on the LHS of decimal tne those have to be picked up over the ones on RHS of decimal.

For Eg. 12345.1234566 --> Output 12345.12345

I dont know if it is the best solution but one of the solution could be using a function called SUBSTRING (0....11) .

I used 11 to include decimal as well. FYI, the STARTINDEX (i.e, 0 ) is included and ENDINDEX (11) in this function is not included.

Let me know if it works ..otherwise i will suggest you a UDF.

Rgds,

Puneet

abhay_rajhans2
Contributor
0 Kudos

Hi Rahul,

You can fix the standard length using function Substring. specify value there as 0 - 10.

Then it will take first 10 Digits(Along with Decimal). If you are having more than 5 digit before decimal how you are going to truncate whether you are going to consider first five or last five digit from decimal point.

abhay_rajhans2
Contributor
0 Kudos

Hi Rahul,

You can fix the standard length using function Substring. specify value there as 0 - 9.

Then it will take first 10 Digits. If you are having more than 5 digit before decimal how you are going to truncate whether you are going to consider first five or last five digit from decimal point.