I understand the warning about floating point decimals in the docs but other languages have suitable rounding functions. For example:
nim:
round(9.779999999999999, 2)
give 9.779999999999999
python:
gives 9.78I'd suggest either
import strutils
echo formatFloat(9.779999999999999,format=ffDecimal,precision=2)
or
import strformat
echo &"{9.779999999999999:0.2f}"
Certain language just likes to go that extra mile to lie to you.
>>> round(9.779999999999999, 2)
9.78
>>> (9.78).hex()
'0x1.38f5c28f5c28fp+3'
>>> round(9.779999999999999, 2).hex()
'0x1.38f5c28f5c28fp+3'
>>> (9.779999999999999).hex()
'0x1.38f5c28f5c28fp+3'
this is now fixed now that we have dragonbox
when true: # D20210513T184615
from math import round
let a = round(9.779999999999999, 2)
doAssert a == 9.78
echo a # before dragonbox: 9.779999999999999, after dragonbox: 9.78, like in python3