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

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download