2010-07-12 225 views
-1

像浮动:红宝石浮子解析

if i == 2.0 i want to get: 2 
if i == 2.3 or 2.23 i want to get: 2.3 or 2.23 
+5

你是在谈论字符串输出还是别的什么? – 2010-07-12 18:11:38

回答

4

使用此表达式。只需将它插入任何你想要的结果:

i.to_i == i ? i.to_i : i