Five Stars

Negative sign at end of the number

Hi,

 

We have a requirement where all decimal values are  in European decimal separator and system, so the negative values are coming from file are as 76,000- 

According to european system I have made following 

 

File.JPG

 

But file is not able to read negative values, please suggest.

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Nine Stars TRF
Nine Stars

Re: Negative sign at end of the number

@pravin_sanadi, did you find this answer usefull or not?

TRF
3 REPLIES
Nine Stars TRF
Nine Stars

Re: Negative sign at end of the number

Hi,

 

In such a case, consider the input as a string (uncheck Advanced separator option).

After the tFileInputDelimited, add a tMap in which you define a var (let say minusFirst) with the following code:

StringHandling.RIGHT(row27.line, 1).equals("-") ? 
	"-" + StringHandling.EREPLACE(row27.line, "-", "") : row27.line 

This will move the minus sign (if any) at the begenning of the string.

Then on the output flow (right part of tMap),  define a double field (let sat signeResult), connect it to the variable minusfirst, replace "." (thousands separator) by "" and "," (decimal separator) by "," and finally cast the result to double.

Here is what the tMap should look like:

Capture.PNG

Or the output flow expression if you prefer:

Double.parseDouble(Var.minusFirst.replaceAll("\\.", "").replace(",", ".")) 

You may prefer to do something similar with a tJavaRow.

Here is the result:

[statistics] connecting to socket on port 4058
[statistics] connected
.--------.
| Input  |
|=------=|
|line    |
|=------=|
|10      |
|10.000,5|
|15-     |
|20,75-  |
'--------'

.------------.
|   Output   |
|=----------=|
|signedResult|
|=----------=|
|10.0        |
|10000.5     |
|-15.0       |
|-20.75      |
'------------'
[statistics] disconnected

Hope this helps.


TRF
Nine Stars TRF
Nine Stars

Re: Negative sign at end of the number

@pravin_sanadi, did you find this answer usefull or not?

TRF
Five Stars

Re: Negative sign at end of the number

Thanks a lot , was busy with lot of implementation so didn't get time.

Once again thanks