Replace Special characters in Deicmal Values

Six Stars

Replace Special characters in Deicmal Values

Hi Team

 

I am i have a string valuue like 1500.00- here i want to get  1500.00

Means any special character other than . should be removed. can you please help me out with this

I am tried with replaceAll("[^\\D.]+", "") but getting wrong results.

 

 

Thanks

Deepthi


Accepted Solutions
Forteen Stars TRF
Forteen Stars

Re: Replace Special characters in Deicmal Values

This one should be enough:

row1.yourField.replaceAll( "[^\\d.]", "" )

For the following sample data:

1000
100.5
500-
10.3@#$%

the result is:

[statistics] connecting to socket on port 3843
[statistics] connected
.---------.
|tLogRow_52|
|=-------=|
|yourField|
|=-------=|
|1000     |
|100.5    |
|500      |
|10.3     |
'---------'
[statistics] disconnected

To convert the result to BigDecimal, just do that:

new BigDecimal(row1.yourField.replaceAll( "[^\\d.]", "" ))

This can be achieve in your tMap or tJavaRow for example.

 

 

 


TRF

All Replies
Thirteen Stars

Re: Replace Special characters in Deicmal Values

@SaranyaKatakam,can you use the below to convert sting to Double using any one.should fix your issue.

 

Double.parseDouble(row3.newColumn1.replaceAll("-", ""))

Double.parseDouble(row3.newColumn1.replace("-", ""))

Manohar B
Six Stars

Re: Replace Special characters in Deicmal Values

Hi

 

Thanks for you replay

 

Not only "-" i want to remove any special character like @#$% etc other than "." and convert it to big decimal

 

Thanks

Deepthi

Forteen Stars TRF
Forteen Stars

Re: Replace Special characters in Deicmal Values

This one should be enough:

row1.yourField.replaceAll( "[^\\d.]", "" )

For the following sample data:

1000
100.5
500-
10.3@#$%

the result is:

[statistics] connecting to socket on port 3843
[statistics] connected
.---------.
|tLogRow_52|
|=-------=|
|yourField|
|=-------=|
|1000     |
|100.5    |
|500      |
|10.3     |
'---------'
[statistics] disconnected

To convert the result to BigDecimal, just do that:

new BigDecimal(row1.yourField.replaceAll( "[^\\d.]", "" ))

This can be achieve in your tMap or tJavaRow for example.

 

 

 


TRF