• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » round to 2 dp with Float.ValueOf()

#1 2012-05-22 14:04:08

buzzy96
Member
Registered: 2012-02-07
Posts: 32

round to 2 dp with Float.ValueOf()

Tags: [tos3.0.0]

hi,

pls let me know any one...

round to 2 dp with Float.ValueOf()?


thx

Offline

#2 2012-05-22 17:02:15

phobucket
Member
Company: Knoetry
Registered: 2010-07-27
Posts: 146
Website

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

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » round to 2 dp with Float.ValueOf()

Board footer

Powered by FluxBB