如何在Ruby中丢弃浮点精度

sea*_*apy 3 ruby floating-point

我想丢弃浮点精度.

(4.43597).discard(3)   =>   4.435 (not 4.436)
Run Code Online (Sandbox Code Playgroud)

我不想用圆形.我该怎么办?我找不到办法.

Dan*_*rth 10

  1. 乘以1000
  2. 转为int
  3. 除以1000.0