瀏覽代碼

* fixed mantis 8434 (wrong precision used in case of |number| < 1,
which when multiplied by 10^x goes from 0.9y to 1.0z, and if a
specific presision is specified)

git-svn-id: trunk@6692 -

Jonas Maebe 18 年之前
父節點
當前提交
e44a9ca4cb
共有 3 個文件被更改,包括 14 次插入1 次删除
  1. 1 0
      .gitattributes
  2. 2 1
      rtl/inc/real2str.inc
  3. 11 0
      tests/webtbs/tw8434.pp

+ 1 - 0
.gitattributes

@@ -8052,6 +8052,7 @@ tests/webtbs/tw8312.pp svneol=native#text/plain
 tests/webtbs/tw8321.pp svneol=native#text/plain
 tests/webtbs/tw8371.pp svneol=native#text/plain
 tests/webtbs/tw8391.pp svneol=native#text/plain
+tests/webtbs/tw8434.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 2 - 1
rtl/inc/real2str.inc

@@ -384,7 +384,8 @@ begin
             begin
               roundStr(temp,spos);
               d := frac(d);
-              dec(currprec);
+              if (f < 0) then
+                dec(currprec);
             end;
           { calculate the necessary fractional digits }
           for fracCount := 1 to currPrec do

+ 11 - 0
tests/webtbs/tw8434.pp

@@ -0,0 +1,11 @@
+uses sysutils;
+
+var
+  x: double;
+begin
+  x := 0.099991;
+  if (Format('%5.2f', [x]) <> ' 0.10') then
+    halt(1);
+  if (Format('%6.3f', [x]) <> ' 0.100') then
+    halt(2);
+end.