diff --git a/src/core/f-math.c b/src/core/f-math.c index ac229c96bb..f8c05dbd88 100644 --- a/src/core/f-math.c +++ b/src/core/f-math.c @@ -260,7 +260,7 @@ /* handle sign */ if (sgn) *cp++ = '-'; - if (trim == DEC_MOLD_PERCENT) e += 2; + if (trim == DEC_MOLD_PERCENT && (digits_obtained > 1 || sig[0] != '0')) e += 2; if ((e > decimal_digits) || (e <= -6)) { /* e-format */ diff --git a/src/tests/run-tests.r3 b/src/tests/run-tests.r3 index 999ddaf3de..ad6882b1a1 100644 --- a/src/tests/run-tests.r3 +++ b/src/tests/run-tests.r3 @@ -15,6 +15,7 @@ dt [ ;- delta time wrap load %units/map-test.r3 wrap load %units/integer-test.r3 wrap load %units/decimal-test.r3 + wrap load %units/percent-test.r3 wrap load %units/money-test.r3 wrap load %units/power-test.r3 wrap load %units/mezz-crypt-test.r3 diff --git a/src/tests/units/percent-test.r3 b/src/tests/units/percent-test.r3 new file mode 100644 index 0000000000..d2e99cce44 --- /dev/null +++ b/src/tests/units/percent-test.r3 @@ -0,0 +1,41 @@ +Rebol [ + Title: "Rebol3 percent test script" + Author: "Oldes, Peter W A Wood" + File: %decimal-test.r3 + Tabs: 4 + Needs: [%../quick-test-module.r3] +] + + +~~~start-file~~~ "percent" + +===start-group=== "form/mold" + --test-- "form" + --assert "0%" = form 0% + --assert "1%" = form 1% + --assert "10%" = form 10% + --assert "0.1%" = form 0.1% + --assert "100%" = form 100% + + --assert "-0%" = form -0% + --assert "-1%" = form -1% + --assert "-10%" = form -10% + --assert "-0.1%" = form -0.1% + --assert "-100%" = form -100% + + --test-- "mold" + --assert "0%" = mold 0% + --assert "1%" = mold 1% + --assert "10%" = mold 10% + --assert "0.1%" = mold 0.1% + --assert "100%" = mold 100% + + --assert "-0%" = mold -0% + --assert "-1%" = mold -1% + --assert "-10%" = mold -10% + --assert "-0.1%" = mold -0.1% + --assert "-100%" = mold -100% +===end-group=== + + +~~~end-file~~~