gmi*_*ile 4 ruby string floating-point digits
是否有任何有价值的Ruby方法来计算浮点数的位数?另外,如何指定to_s浮点数的精确时间?
# Number of digits
12345.23.to_s.split("").size -1 #=> 7
# The precious part
("." + 12345.23.to_s.split(".")[1]).to_f #=> .023
# I would rather used
# 12345.23 - 12345.23.to_i
# but this gives 0.22999999999563
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6027 次 |
| 最近记录: |