# 转为 IntstrNumber = "42"number = strNumber.to_i# 转换为 FloatstrPi = "3.14"piFloat = strPi.to_f# 第二种方法strHalf = "0,5"half = strHalf.sub(",", ".").to_fputs "number is #{number}"puts "piFloat is #{piFloat}"puts "half is #{half}"