You are not logged in.

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

rojas
Member
2 posts

[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 14:47:20

kzone
Member
1458 posts

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"

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
mini_116230_convert.jpg


Manage your data before data manages You !!!
http://www.synotis.fr/

Offline

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

rojas
Member
2 posts

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

Board footer

Talend Contributor Agreement - Talend Website Privacy Policy