ruby - string.to_f precision issue when the value trailed by two zeros -
i input string "400.00" , need display 400.00.
expected float_value :400.00
i used to_f task since to_i homecoming 400 alone. code is
x="400.00" float_value=x.to_f but in case, getting output 400.0 not acceptable case.
current float_value :400.0
both equal , have no difference, not calculation purpose, other display purpose.
use sprintf fomatting:
sprintf("%.2f", 400) #=> "400.00" ruby
No comments:
Post a Comment