summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/bigdecimal
diff options
context:
space:
mode:
authorshigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-05 09:32:09 +0000
committershigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-05 09:32:09 +0000
commitf2c49270e75313b9438bfb80bd99925dbe9ca1b2 (patch)
treee56ae5f963714c888c288531a228684a45d212be /ext/bigdecimal/lib/bigdecimal
parent70903de1cdd517cc5c4f679e33d0a6ae59d8063a (diff)
Bug in to_digits fixed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal')
-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 de5dae85464..7a4a1e5e2d5 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