Incorrect client side float to string conversion

It’s not exactly a bug - it’s a difference in precision for the str representation of the same number.

You can try doing the following on the server and client

format(86721.1, '.16g') # 16 significant figures
format(86721.1, '.15g')

You’ll likely get the 82151.10000000001 for 16g but not for 15g.
It’s the problem of floating point arithmetic from the python docs

I’d suggest going with a format str approach to display floating point numbers.
(which you already mentioned)

format(82151.1, '.2')
f'{82151.1: .2}'


Worth noting that, although the javascript work around works in this case.
It doesn’t work in general. e.g.

x = .1 + .1 + .1
# 0.30000000000000004

So i wouldn’t recommend that approach.

4 Likes