@Stefan_Salewski @Nam > It`s a bit hard to believe that this is a serious 
question because of > But maybe you missed that and have no CS experience. > 
That is not a Nim issue, but occurs from representation of floats in the CPU

it's a serious question, no need to question about OP's CS credentials, and it 
is indeed a nim issue.

Here's a minimal version: 
    
    
    echo 'echo(26.0 * 2.54)' | nim c -r -
    66.04000000000001
    
    
    Run

python does a better job: 
    
    
    python3 -c 'print(26.0*2.54)'
    66.04
    
    
    Run

without sacrificing precision: 
    
    
    python3 -c 'print(1/0.3)'
    3.3333333333333335
    
    
    Run

the fix is to port ryu to nim stdlib, which is tracked here 
[https://github.com/nim-lang/Nim/issues/13365](https://github.com/nim-lang/Nim/issues/13365)
 there's already a POC nimble pkg from @disruptek
    
    
    echo 'import pkg/ryu; echo f2s(26.0*2.54)' | nim c -r -
    6.604e1
    
    
    Run

which, if 
[https://github.com/disruptek/ryu/issues/4](https://github.com/disruptek/ryu/issues/4)
 is addressed, could have an option to customize format and display like in 
python: 66.04 instead of 6.604e1

Reply via email to