When printing floats, ruby prints 1234.0
with only one 0
after the period. How can I f开发者_C百科orce ruby to print two 0
s?
Format strings to the rescue:
>> puts "%.2f" % 1.0 #=> nil
1.00
When printing floats, ruby prints 1234.0
with only one 0
after the period. How can I f开发者_C百科orce ruby to print two 0
s?
Format strings to the rescue:
>> puts "%.2f" % 1.0 #=> nil
1.00
精彩评论