cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove trailing zeroes

Occasional Contributor

How to remove trailing zeroes

I have to match two responses. One gives response say A like 113.00 and the other say B as 113 . I want to remove the trailing zeroes from A. How do I do it

 

I am reading the field value of A as below 

 

def gainLoss =slurpRest.getRealizedByAccountResponse.securityList.e[b].GainLossList.RealizedGainLoss.text()

 

I tried using the below but get an error

 

def gainlossbig = new BigDecimal(gainLoss).setScale(0)

 

but get the error as 'Error in assertion script :null'

 

Please tell how do I remove the trailing zeroes in this case?

 

 

 

5 REPLIES 5
Community Hero

Re: How to remove trailing zeroes

Instead you can coierce it to same data type.

For instance: You may variable instead of static value below as well

//Below shows the example of coiercing to a specific type
def actualAmount = 113.00 as Double
def expectedAmount = 113 as Double
assert actualAmount == expectedAmount


Regards,
Rao.
Occasional Contributor

Re: How to remove trailing zeroes

Doesnt work. Get an error "Cannot cast object with class 'Java.lang.string' to class 'double'

Community Hero

Re: How to remove trailing zeroes

Ok, then you need to provide the data.


Regards,
Rao.
Occasional Contributor

Re: How to remove trailing zeroes

Sorry . I did not get you. What data do you need? The Response ?

Community Hero

Re: How to remove trailing zeroes

How should one reproduce what you are reporting? The code snippet provided to you does not throw the reported error, right?


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors