trnc
trnc

Reputation: 21577

Ruby float with double 0

When printing floats, ruby prints 1234.0 with only one 0 after the period. How can I force ruby to print two 0s?

Upvotes: 8

Views: 6003

Answers (1)

Michael Kohl
Michael Kohl

Reputation: 66837

Format strings to the rescue:

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

Upvotes: 24

Related Questions