The decimal value converting to scientific notation in API response if the value is big number

135 Views Asked by At

I am working on a GET Request where it should suppose to return the one of key value in the response as 400000000000.00 but in karate framework the key value is being displaying in exponential format as 4E+11 in response.

But when executing the same request using postman, its showing the value in response as expected in number format

I have tried by going through the document but dont find any required details. The smaller numbers displayed in number format and observed the issue only for the bigger numbers like 12 digits as per my observation

Since the conversion happening in response details automatically

Expected response from karate: {"balanceAmount" : 400000000000.00}

But the Karate framework returning response as {"balanceAmount" : 4E+11}

1

There are 1 best solutions below

0
Peter Thomas On

Karate parses data into Java primitives and 99.9% of the time, this works fine.

As someone mentioned in the comments, when you need to produce large numbers, you can use the BigDecimal class: https://github.com/karatelabs/karate#large-numbers

Another way to send a request with the exact numbers you want is to use a string, and make sure your Content-Type header is set correctly. For example:

* url 'https://httpbin.org/post'
* header Content-Type = 'application/json'
* request '{ "num": 400000000000.00 }'
* method post
* match response.json.num == 400000000000

You can try this yourself, and note how Karate will match correctly and handle even large numbers.

Another tip is that Karate always stores the response as bytes, and it will be available as responseBytes. Converting this to a string will allow you to see the "actual" response.

* string temp = responseBytes
* assert temp.contains('"num": 400000000000.0')