[resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

One Star

[resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

Hello,
I have a job that allows you to extract data from Excel and SQL Table to store in a SQL server database.
I did the transformation fields String float.
But I do not understand why I have this error:


Exception in component tMap_2
java.lang.NumberFormatException: For input string: "0,0506609517898527"
Has sun.misc.FloatingDecimal.readJavaFormatString (Unknown Source)
Has java.lang.Float.parseFloat (Unknown Source)
Has bdd_budget_icp.bud_0_1.Bud.tFileInputDelimited_1Process (Bud.java:2332)
Has bdd_budget_icp.bud_0_1.Bud.runJobInTOS (Bud.java:4470)
Has bdd_budget_icp.bud_0_1.Bud.main (Bud.java:4291)
disconnected


Please find enclosed my tmap and my Job.
What is the problem please? and how to solve it?
Regards

Accepted Solutions
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

The problem was the comma. I resolved; in each column that I want to convert I do this:

fromMainFlow.Tx_RFA! = null && fromMainFlow.Tx_RFA.trim ().length ()> 0? 
BigDecimal.valueOf (Double.valueOf (fromMainFlow.Tx_RFA.replaceAll (",", "."))): null

Thank you all for your help.
See you soon.
have a nice day

All Replies
Moderator

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

Hi slim1501,

What's your input source data type? How did you set your tMap? Did you set length in schema setting? Could you please upload your tmap editor screenshot into forum?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

If you replace coma to dot then it will work. see the below statement.
new BigDecimal("0,0506609517898527".replace(",","."))

or you can use below methods to convert it. 
String text = "1,234567";
NumberFormat nf_in = NumberFormat.getNumberInstance(Locale.GERMANY);
double val = nf_in.parse(text).doubleValue();
NumberFormat nf_out = NumberFormat.getNumberInstance(Locale.UK);
nf_out.setMaximumFractionDigits(3);
String output = nf_out.format(val);
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

hello,
My data source is a file (.csv). type columns String.
I set the size to 255 for each column.
enclosed my print-screen.
I tried with Double too, but it does not work
like this:

Relational.ISNULL (fromMainFlow.CST_PROD_KG) == true? null: Double.parseDouble (fromMainFlow.CST_PROD_KG)
 

Exception in component tMap_2
java.lang.NumberFormatException: For input string: "0,05066095178985277"
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Double.parseDouble(Unknown Source)
    at bdd_budget_icp.bud_0_1.Bud.tFileInputDelimited_1Process(Bud.java:2345)
    at bdd_budget_icp.bud_0_1.Bud.runJobInTOS(Bud.java:4482)
    at bdd_budget_icp.bud_0_1.Bud.main(Bud.java:4303)

Yours
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

can you try the solution i provided. I am sure that will work for you.
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

First of all, thank you for your help.
I do not know where to put your code !! Is it in the Tmap (in each destination field)?
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

My bad, I should explain it in better way. 
so first line of code you can implement it directly in tMap.
new BigDecimal(row1.yourcolumnName.replace(",","."))

but for second solution, you have to create routine and add static method which return BigDecimal value, then write down mention code that can be work. 
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

sorry, I'm a beginner, I could not do it (routine) !! Smiley Sad
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

Below link will help you to do that, but have you tried first solution? and what is the output?
Creating a user routine and call it in a Job
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

I got this error:
Exception in component tMap_2
java.lang.NumberFormatException
Has java.math.BigDecimal. <init> (Unknown Source)
Has java.math.BigDecimal. <init> (Unknown Source)
Has bdd_budget_icp.bud_0_1.Bud.tFileInputDelimited_1Process (Bud.java:3429)
Has bdd_budget_icp.bud_0_1.Bud.runJobInTOS (Bud.java:4067)
Has bdd_budget_icp.bud_0_1.Bud.main (Bud.java:3888)

Do I need to change something my database SQL server data (output)?
CREATE TABLE BUDGET_CA
(current_file varchar(255) PRIMARY KEY NOT NULL,
Date_Bud Date,
code_CLI  varchar(255),
NAT_CODE varchar(255),
code_article varchar(255),
ACTION_BUD2014 varchar(255),
Zone_Geo varchar(255),
Tx_RFA DECIMAL(19,5) ,
CST_PROD_KG DECIMAL(19,5),
CST_LOG_KG DECIMAL(19,5) ,
Kilo_BU DECIMAL(19,5) ,
CA_BUD DECIMAL(19,5) ,
CMA_BUD DECIMAL(19,5) ,
Cpt_Comptbl_F varchar(255),
Code_Analytiques varchar(255)
);
Here join a screen-prints of my CSV file
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

what coma denotes in all the fields? is it a thousand separator or  a decimal point? 
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

It's a decimal point
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

then below statement should work, use below statement for all the columns which has numeric data and you want to convert it to big decimal. 
new BigDecimal(row1.tx_rfa.replace(",","."))
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

I'll try,
But,Typing my database should I leave it as it is?

CREATE TABLE BUDGET_CA
(CURRENT_FILE varchar (255) NOT NULL PRIMARY KEY,
Date_Bud Date,
code_CLI varchar (255),
NAT_CODE varchar (255),
code_article varchar (255),
ACTION_BUD2014 varchar (255),
Zone_Geo varchar (255),
Tx_RFA DECIMAL (19,5)
CST_PROD_KG DECIMAL (19,5)
CST_LOG_KG DECIMAL (19,5)
Kilo_BU DECIMAL (19,5)
CA_BUD DECIMAL (19,5)
CMA_BUD DECIMAL (19,5)
Cpt_Comptbl_F varchar (255),
Code_Analytiques varchar (255)
);

Thank you for your help.
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

I tried it, it did not work, I got this error:

Exception in component tMap_2
java.lang.NumberFormatException
Has java.math.BigDecimal. <init> (Unknown Source)
Has java.math.BigDecimal. <init> (Unknown Source)
Has bdd_budget_icp.bud_0_1.Bud.tFileInputDelimited_1Process (Bud.java:2296)
Has bdd_budget_icp.bud_0_1.Bud.runJobInTOS (Bud.java:4089)
Has bdd_budget_icp.bud_0_1.Bud.main (Bud.java:3910)


I do not understand why it does not work !!!!!
Five Stars

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

can you show me your input component schema and tmap output schema. 
One Star

Re: [resolved] Error in a Tmap : java.lang.NumberFormatException: For input string

The problem was the comma. I resolved; in each column that I want to convert I do this:

fromMainFlow.Tx_RFA! = null && fromMainFlow.Tx_RFA.trim ().length ()> 0? 
BigDecimal.valueOf (Double.valueOf (fromMainFlow.Tx_RFA.replaceAll (",", "."))): null

Thank you all for your help.
See you soon.
have a nice day