Because `num` is being converted to binary (base2) from decimal (base10) in the 
source code, you are seeing a artifact of decimal-to-binary conversion.

One work-around is to store the decimal numbers in decimal form. My library, 
`decimal128` does this but a `floor` function as not been written for the 
library. (A lot of things have not been written for it yet.) A work-around is 
to convert it to an integer temporarily, like so:
    
    
    import decimal128
    
    var
      num = newDecimal128("786.654")
      intPart = num.toInt
      wholeNumber = newDecimal128(intPart, scale=3)
      decPart = num - wholeNumber
    
    echo decPart
    
    
    Run

Details at <https://nimble.directory/pkg/decimal128>

Reply via email to