【发布时间】:2011-12-05 08:24:02
【问题描述】:
如果在 Ruby 中有一个与 R's signif 等效的函数,那就太好了。
例如:
>> (11.11).signif(1)
10
>> (22.22).signif(2)
22
>> (3.333).signif(2)
3.3
>> (4.4).signif(3)
4.4 # It's usually 4.40 but that's OK. R does not print the trailing 0's
# because it returns the float data type. For Ruby we want the same.
>> (5.55).signif(2)
5.6
【问题讨论】:
-
这个问题适合scicomp.stackexchange.com吗?
标签: ruby floating-point significant-digits