如何用尾随零舍入一个非常小的浮点数?

Ric*_*ram 2 ruby floating-point numbers rounding

目前我的代码呈现数字:

x = 0.000092627861766
p x
Run Code Online (Sandbox Code Playgroud)

像 BigInt 格式这样的东西:

=> 9.0e-05 
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以调用变量来返回一个舍入的浮点数(以数字或字符串格式),使得:

x.some_method
# Always show N number of digits after the initial decimal point.
=> 0.00009263 
OR 
=> "0.00009263"
Run Code Online (Sandbox Code Playgroud)

Fer*_*and 5

您可以设置要显示的位数:

p "%0.08f" % x # => "0.00009263"
Run Code Online (Sandbox Code Playgroud)