• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Convert BigDecimal to Float

#1 2013-08-27 14:42:38

rojas
New member
Registered: 2013-08-28
Posts: 2

[resolved] Convert BigDecimal to Float

Hi,

I want convert BigDecimal to Float.

I do this :

Float.parsefloat(String.valueof(BigDecimal))

For BigDecimal = "123456.12000000000" the result is good, I obtain the float value 123456.12

BUT

For BigDecimal = "1234567.12000000000" the result is not good, I obtain the float value 1234567.1 instead off 1234567.12

AND

For BigDecimal = "123456789.12000000000" the result is not good, I obtain the float value 1.23456792E8 instead off 123456789.12

What I must do to resolve this problem ?

Thank for help
Bests regards

Josť Rojas

Offline

#2 2013-08-27 15:47:20

kzone
Member
Company: Synotis
Registered: 2008-07-06
Posts: 1103
Website

Re: [resolved] Convert BigDecimal to Float

hi,

when you convert BigDecimal to Float or Double you lose precision. BigDecimal is the only way to be sure to keep all decimal number.

try to put precision to 2 (after dot) with double type.
result with "1234567.12000000000"

Code:

Starting job bigd at 15:45 27/08/2013.

[statistics] connecting to socket on port 4009
[statistics] connected
1234567.12
[statistics] disconnected
Job bigd ended at 15:45 27/08/2013. [exit code=0]

regards
laurent


Uploaded Images


do Svg your graphical language !!!

Offline

#3 2013-08-28 15:22:39

rojas
New member
Registered: 2013-08-28
Posts: 2

Re: [resolved] Convert BigDecimal to Float

Hi,

It's ok now using double type with precision to 2 (after dot)

Thank for your help

regards

Josť Rojas

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Convert BigDecimal to Float

Board footer

Powered by FluxBB