From 983861c1dc58544935805c842de0a034d4289253 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 11 Aug 2013 14:53:11 -0400 Subject: [PATCH] Value: change to_s to use sprintf() --- lib/gnucash/value.rb | 2 +- spec/gnucash/value_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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