• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Numbers being rounded ?

#1 2011-08-18 14:36:02

lesjar2509
Member
Registered: 2010-11-11
Posts: 30

[resolved] Numbers being rounded ?

I have created a context variable for example   mxccy  and set this to be a float   i.e. a floating number
I am taking a report text file to convert it into an MYSQL database table
I mapped out the fields across the report line  and for my value example   AMOUNT as a string

The value I read for rpccy  was 10,297,529.87 but it ended up as 10297530.00

You can try this out with the following code in tJavaFlex !!!!

String toparse = "10,297,529.87";
if(toparse.equals("")|| toparse == null)
    toparse = "0.00";
else {
    toparse = toparse.replace(" ","");
    toparse = toparse.replace(",","");

};
String toparse1 = "10,297,529.87";
if(toparse1.equals("")|| toparse1 == null)
    toparse1 = "0.00";
else {
    toparse1 = toparse1.replace(" ","");
    toparse1 = toparse1.replace(",","");
    toparse1 = toparse1.replace(".","");
};
System.out.print("Float Number "+Float.parseFloat(toparse)+" ");
  System.out.print("Integer Number "+Integer.parseInt(toparse1)+" ");
  System.out.print("Fixed Number "+Numeric.convertImpliedDecimalFormat("99999999999999999V99",toparse1)+" ");


This will give you the results as
Float Number 1.029753E7 Integer Number 1029752987 Fixed Number 1.029753E7

Now all I need is a means of converting a Text value   10,297,529.87  into an MYSQL field mapped as   DECIMAL(19,2)   i.e. 17 leading digits with 2 decimal places.

Any suggestions that I coud use and able to store this large value in an approprite CONTEXT type  in tJavaRow  for use later in a tMap component .

Offline

#2 2011-08-18 15:10:17

lesjar2509
Member
Registered: 2010-11-11
Posts: 30

Re: [resolved] Numbers being rounded ?

Another test shows   toparse1 = "12345678"  gives  Fixed Number 123456.78
BUT !!!!!!!!    toparse1 = "123456789"  gives              Fixed Number 1234567.9
AND !!!!!!!!   toparse1 = "123456712";  gives             Fixed Number 1234567.1    thus rounding and truncation is happening

Offline

#3 2011-08-19 05:27:40

alevy
Member
Registered: 2009-11-20
Posts: 1477

Re: [resolved] Numbers being rounded ?

Seems to me to be a problem with Floats in Java itself.  Why not use BigDecimals?

Offline

#4 2011-08-19 15:42:24

lesjar2509
Member
Registered: 2010-11-11
Posts: 30

Re: [resolved] Numbers being rounded ?

Used LONG integers to store in MYSQL then process using MYSQL procedure back to decimal data  i.e divide by 100.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Numbers being rounded ?

Board footer

Powered by FluxBB