0

react.js axios is rounding up Long values, how this can be resolved ?

As I have previously checked all my api's via postman, I can surely tell you that my apis are just fine.

Now the problem is when I send I Long value to react.js client, it rounds up the value, so when I try to retrieve it back it creates problem.

Here is a snap:

enter image description here

  • Second value is what I sent

  • First value is what I got in client

Server - Spring Boot with h2,jpa

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
  • 1
    That's way bigger than `Number.MAX_SAFE_INTEGER` value. You need to send it as a string from server side – adiga Jan 01 '20 at 12:06
  • 1
    Also, please go through [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) – adiga Jan 01 '20 at 12:11
  • Just add transformResponse to your axios config and use json-big-int to turn the int into a big-int `const config = { transformResponse: [(data: any) => JSONbig.parse(data)], }; const { data } = await axios.get(url, config);` – cwallenwein Sep 27 '21 at 19:43
  • Addition to my comment from above: import json-bigint like this `const JSONbig = require("json-bigint")({ useNativeBigInt: true });` That way the big int will be stored as a js native big int. – cwallenwein Sep 27 '21 at 20:16

0 Answers0