Friday, August 12, 2022

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

Issue

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.



Answered By - Totalys
Answer Checked By - Gilberto Lyons (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.