Search code examples
decimalpostmanpostman-collection-runner

How to get all decimal digits provided in a json response in Postman?


I Have an API that returns the following (example):

{"rate": 3.568640920671274015}

In the Tests space, I try to retrieve the rate value:

pm.test("Set variables", function () {
var jsonData = pm.response.json(); 
pm.environment.set('new-rate', jsonData.rate);

But as result, I get only:

3.568640920671274

It seems that Postman is truncating the result. Is there a way to avoid that?

PS: The value came from a decimal. (inside de API).


Solution

  • Doing something like this:

    pm.environment.set('new-rate', jsonData.rate.toPrecision(18));
    

    worked to me.