Index: test/testBigDecimal.rb =================================================================== --- test/testBigDecimal.rb (revision 5172) +++ test/testBigDecimal.rb (working copy) @@ -142,6 +142,13 @@ test_equal 1.0-one, 0.0 test_equal("1.0", BigDecimal.new('1.0').to_s('F')) +test_equal("0.1", BigDecimal.new('0.1').to_s('F')) +test_equal("0.1", BigDecimal.new('.1').to_s('F')) +test_equal("0.001", BigDecimal.new('.001').to_s('F')) +test_equal("0.001", BigDecimal.new('.001').to_s('F')) +test_equal("0.1", BigDecimal.new('.1').to_s('F')) +test_equal("1.0", BigDecimal.new('1.').to_s('F')) +test_equal("1.0", BigDecimal.new('1').to_s('F')) test_equal("0.0", BigDecimal.new('0.0').to_s) test_equal(BigDecimal("2"), BigDecimal("1.5").round) Index: src/org/jruby/RubyBigDecimal.java =================================================================== --- src/org/jruby/RubyBigDecimal.java (revision 5172) +++ src/org/jruby/RubyBigDecimal.java (working copy) @@ -684,7 +684,7 @@ String s = removeTrailingZeroes(unscaled); if("".equals(s)) { build.append("0"); - } else { + } else { build.append(s); } } else { @@ -703,13 +703,16 @@ build.append("E").append(exponent); out = build.toString(); } else { - int ix = abs.toString().indexOf('.'); - String whole = unscaled; - String after = null; - if(ix != -1) { - whole = unscaled.substring(0,ix); - after = unscaled.substring(ix); + String values[] = abs.toString().split("\\."); + String whole = "0"; + if (values.length > 0) { + whole = values[0]; } + String after = "0"; + if (values.length > 1) { + after = values[1]; + } + int signum = value.signum(); StringBuffer build = new StringBuffer(); build.append(signum == -1 ? "-" : (signum == 1 ? (pos_sign ? (pos_space ? " " : "+" ) : "") : ""));