cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to Truncate value from 3rd decimal without rounding off

former_member593220
Participant
0 Kudos

Hi All,

For one of the field NETPR, PI is getting money with decimal values. But my requirement is to truncate all the values from 3rd decimal without rounding of the value.

For example: If NETPR is 5678.546 then output value should be 5678.54 only, but PI should not round off this value to 5678.55.

unfortunately am getting round off output in test results after using "formatNumber" function also.

Below is my mapping :

Can any one please tell me if it can able to handle with UDF help or with in graphical mapping.?

Thanks in Advance.!

--

With regards

Raj

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Raj,

You can use this UDF:

Since you are already using formatNum + replaceString in graphical, there is no need to check it inside UDF

Testing

Regards,

Mark

former_member593220
Participant
0 Kudos

Hi Mark,

Thanks a lot code works for me as expected.

--

Regards

Raj

Answers (2)

Answers (2)

former_member182412
Active Contributor
0 Kudos

Hi Raj,

Use below UDF.

Execution type : Single Values


public String decimalNotRounding(String input, Container container) throws StreamTransformationException {

  Double f1 = Double.parseDouble(input);

  DecimalFormat df = new DecimalFormat(".00");

  df.setRoundingMode(RoundingMode.DOWN);

  return df.format(f1);

  }

Regards,

Praveen.

iaki_vila
Active Contributor
0 Kudos

Hi Rajm

Check 10 UDF  Raghuraman Sritharan suggestion in his blog

REgards.