summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/bigdecimal/util.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal/util.rb')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index de5dae8546..7a4a1e5e2d 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -33,17 +33,14 @@ end
class BigDecimal < Numeric
# to "nnnnnn.mmm" form digit string
def to_digits
- if self.nan? || self.infinite?
+ if self.nan? || self.infinite? || self.zero?
self.to_s
else
- s,i,y,z = self.fix.split
+ i = self.to_i.to_s
s,f,y,z = self.frac.split
- if s > 0
- s = ""
- else
- s = "-"
- end
- s + i + "." + f
+ f = f.gsub(/0+$/,"")
+ f = "0" if f==""
+ i + "." + ("0"*(-z)) + f
end
end