diff --git a/lib/gnucash/value.rb b/lib/gnucash/value.rb index 1abaf73..dce940b 100644 --- a/lib/gnucash/value.rb +++ b/lib/gnucash/value.rb @@ -25,7 +25,7 @@ module Gnucash end def to_s - (@val / 100.0).round(2).to_s + sprintf("%.02f", @val / 100.0) end end end diff --git a/spec/gnucash/value_spec.rb b/spec/gnucash/value_spec.rb index c25ab89..61760a2 100644 --- a/spec/gnucash/value_spec.rb +++ b/spec/gnucash/value_spec.rb @@ -30,5 +30,9 @@ module Gnucash c = a - b c.to_s.should == "-123.99" end + + it "formats the number with two decimal places" do + Value.new("1400/100").to_s.should == "14.00" + end end end