Forum Discussion

swprabhu's avatar
swprabhu
Occasional Contributor
6 years ago

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

  • nmrao's avatar
    nmrao
    Champion Level 3

    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
  • swprabhu's avatar
    swprabhu
    Occasional Contributor

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

    • nmrao's avatar
      nmrao
      Champion Level 3
      Ok, then you need to provide the data.
  • swprabhu's avatar
    swprabhu
    Occasional Contributor

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

    • nmrao's avatar
      nmrao
      Champion Level 3
      How should one reproduce what you are reporting? The code snippet provided to you does not throw the reported error, right?