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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog