开发者

Ruby float with double 0

开发者 https://www.devze.com 2023-02-26 04:22 出处:网络
When printing floats, ruby prints 1234.0 with only one 0 after the period. How can I f开发者_C百科orce ruby to print two 0s?Format strings to the rescue:

When printing floats, ruby prints 1234.0 with only one 0 after the period. How can I f开发者_C百科orce ruby to print two 0s?


Format strings to the rescue:

>> puts "%.2f" % 1.0 #=> nil
1.00
0

精彩评论

暂无评论...
验证码 换一张
取 消