round to 2 dp with Float.ValueOf()

One Star

round to 2 dp with Float.ValueOf()

hi,
pls let me know any one...
round to 2 dp with Float.ValueOf()?

thx
One Star

Re: round to 2 dp with Float.ValueOf()

Hi buzzy,
What is the input data type? Also, float is only 32bit, so depending on the size of your number, you might lose precision after you round. Double or BigDecimal may be a better choice.
For a double, you could use this to round: (Math.round(myField*100.0))/100.0
For a BigDecimal, you could use this to round: myField.setScale(2, BigDecimal.ROUND_HALF_UP)
Thanks,
Ben

What’s New for Talend Spring ’19

Join us live for a sneak peek!

Sign up now

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download