File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
spec/ruby/library/bigdecimal Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,13 @@ def frac
207
207
end
208
208
209
209
def to_s ( format = 'E' )
210
- if finite?
210
+ if zero?
211
+ if sign == SIGN_NEGATIVE_ZERO
212
+ '-0.0'
213
+ else
214
+ '0.0'
215
+ end
216
+ elsif finite?
211
217
float_format = format [ -1 ] == 'F' || format [ -1 ] == 'f'
212
218
space_frequency = format . to_i
213
219
prefix = if self > 0 && [ ' ' , '+' ] . include? ( format [ 0 ] )
Original file line number Diff line number Diff line change 15
15
@bigdec . inspect . should == "0.12345678e4"
16
16
end
17
17
18
+ it "does not add an exponent for zero values" do
19
+ BigDecimal ( "0" ) . inspect . should == "0.0"
20
+ BigDecimal ( "+0" ) . inspect . should == "0.0"
21
+ BigDecimal ( "-0" ) . inspect . should == "-0.0"
22
+ end
23
+
18
24
it "properly cases non-finite values" do
19
25
BigDecimal ( "NaN" ) . inspect . should == "NaN"
20
26
BigDecimal ( "Infinity" ) . inspect . should == "Infinity"
Original file line number Diff line number Diff line change 19
19
@bigdec . to_s . should =~ /^0\. [0-9]*e[0-9]*$/
20
20
end
21
21
22
+ it "does not add an exponent for zero values" do
23
+ BigDecimal ( "0" ) . to_s . should == "0.0"
24
+ BigDecimal ( "+0" ) . to_s . should == "0.0"
25
+ BigDecimal ( "-0" ) . to_s . should == "-0.0"
26
+ end
27
+
22
28
it "takes an optional argument" do
23
29
lambda { @bigdec . to_s ( "F" ) } . should_not raise_error ( )
24
30
end
You can’t perform that action at this time.
0 commit comments