OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why are positive decimals coming from python flask backend randomly getting converted into negative number on javascript frontend?

  • Thread starter Thread starter sohdata
  • Start date Start date
S

sohdata

Guest
Backend - Flask and MySQL DB, Frontend - React.js, JavaScript.

Notice the record with customer_id=528.

I logged the records on the backend:

Code:
[
{'customer_id': 309, 'net_balance': Decimal('30000.00000000'), 'vendor_id': -1}, 
{'customer_id': 528, 'net_balance': Decimal('27962.00000000'), 'vendor_id': 139},
{'customer_id': 305, 'net_balance': Decimal('20000.00000000'), 'vendor_id': -1}, 
{'customer_id': 71, 'net_balance': Decimal('20000.00000000'), 'vendor_id': -1},
]

When I log the API response on the frontend, the response:

Code:
[
    {
        "customer_id": 309,
        "net_balance": 30000,
        "vendor_id": -1
    },
    {
        "customer_id": 528,
        "net_balance": -2038,
        "vendor_id": 139
    },
    {
        "customer_id": 305,
        "net_balance": 20000,
        "vendor_id": -1
    },
    {
        "customer_id": 71,
        "net_balance": 20000,
        "vendor_id": -1
    }
]

Why is Decimal('27962.00000000') getting converted into -2038, but the others are fine?

<p>Backend - Flask and MySQL DB, Frontend - React.js, JavaScript.</p>
<p>Notice the record with <code>customer_id=528</code>.</p>
<p>I logged the records on the backend:</p>
<pre><code>[
{'customer_id': 309, 'net_balance': Decimal('30000.00000000'), 'vendor_id': -1},
{'customer_id': 528, 'net_balance': Decimal('27962.00000000'), 'vendor_id': 139},
{'customer_id': 305, 'net_balance': Decimal('20000.00000000'), 'vendor_id': -1},
{'customer_id': 71, 'net_balance': Decimal('20000.00000000'), 'vendor_id': -1},
]
</code></pre>
<p>When I log the API response on the frontend, the response:</p>
<pre><code>[
{
"customer_id": 309,
"net_balance": 30000,
"vendor_id": -1
},
{
"customer_id": 528,
"net_balance": -2038,
"vendor_id": 139
},
{
"customer_id": 305,
"net_balance": 20000,
"vendor_id": -1
},
{
"customer_id": 71,
"net_balance": 20000,
"vendor_id": -1
}
]
</code></pre>
<p>Why is <code>Decimal('27962.00000000')</code> getting converted into <code>-2038</code>, but the others are fine?</p>
 
Top