I have an application where the backend uses python with data in a pandas dataframe, and the frontend uses javascript. I am running into an issue where they round differently. Python rounds to the nearest even number if the distance between 2 numbers is equal, while javascript rounds up in that case.
For example, python's round(0.1250, 2)
returns 0.12
. In javascript there is no "round to n decimals" function, so the workaround often used is Math.round(0.1250*100)/100
which rounds to 0.13
.
I have tried getting javascript to round like python, but have had no luck, so my question now is, can I force python to round like javascript somehow, specifically on a panda's dataframe, but I think that just uses the builtin round
function
Asked
Active
Viewed 47 times
2

Dolf Andringa
- 2,010
- 1
- 22
- 36