Hi all, now I am converting a string to float.
var e = "165.5625".parseFloat
echo fmt("{e:1.3f}")
The result is 165.562, which is wrong.
The result I want to get is 165.563. I searched the nim class library and found no related functions. Is there such a function? thanks
There is in math:
https://nim-lang.org/docs/math.html#round%2CT%2Cint
(generally searching here https://nim-lang.org/docs/theindex.html is a good idea)
i don't see that any particular rounding style is inherently any more correct than any other (and there are what, 6 different ways?*)
but the way that formatBiggestFloat (and therefore strformat) works is to use sprintf, which, yes, uses round to even.
[*] there's 8 specified for IEEE Decimal arithmetic -- I hadn't heard of round-05 up that's weird