Seven Stars

Null handling for Integer,Float type

Hi everyone,

 

Can anyone say how to validate integer,float columns which have empty instead of the string "null"

I'm using below code but still, I'm getting an error like For input string: " "

 

I know in input one integer column is coming as empty.

 

Please help me to validate in the correct way.

 

 

 

 

  • Data Integration
7 REPLIES
Nine Stars

Re: Null handling for Integer,Float type

in advanced properties for input component - check Trim All column

 

excluding rare cases when spaces is mandatory it help a lot in many cases

 

-----------
Six Stars

Re: Null handling for Integer,Float type

You can try

 

yourStringData.matches("[-+]?\\d*\\.?\\d+")

 

- JG
Seven Stars

Re: Null handling for Integer,Float type

Hi,

I'm getting below error after trying possible ways.

 

Exception in component tMap_1 (Local_Booking)
java.lang.NumberFormatException
at java.math.BigDecimal.parseExp(BigDecimal.java:647)
at java.math.BigDecimal.<init>(BigDecimal.java:488)
at java.math.BigDecimal.<init>(BigDecimal.java:383)
at java.math.BigDecimal.<init>(BigDecimal.java:806)
at np_old.local_booking_0_1.Local_Booking.tFileInputExcel_1Process(Local_Booking.java:3492)
at np_old.local_booking_0_1.Local_Booking.runJobInTOS(Local_Booking.java:4571)
at np_old.local_booking_0_1.Local_Booking.main(Local_Booking.java:4420)

Seven Stars

Re: Null handling for Integer,Float type

Hi,

 

Here is the code I'm using for string to Bigdecimal

 

row1.ORDER_DISCOUNT.equals("null")?null:new BigDecimal(row1.ORDER_DISCOUNT) 

Nine Stars

Re: Null handling for Integer,Float type

try this:

row1.ORDER_DISCOUNT==null||row1.ORDER_DISCOUNT.equals("")?null:new BigDecimal(row1.ORDER_DISCOUNT)
-----------
Seven Stars

Re: Null handling for Integer,Float type

Hi @vapukov & @h311,

Thanks for your help.

 

It's working :-)

 

Eleven Stars

Re: Null handling for Integer,Float type

Here is a routine you can use......

 

    public static boolean isNumeric(String data){
    	boolean returnVal = true;
    	
    	try{
    		Integer.parseInt(data);
    	}catch(Exception ex){
    		returnVal = false;
       	}
    	return returnVal;
    }

I use that to test if String values represent Integers. Just tweak the code to cater for Floats if you need to. It will return true or false based on what you supply the String parameter

Rilhia Solutions