Quellcode durchsuchen

* don't add a thousands separator in FormatFloat if there are no digits
before it because the value is too small, regardless of what the format
pattern sepcifies (patch by Bart Broersma, mantis #13076)

git-svn-id: trunk@23095 -

Jonas Maebe vor 12 Jahren
Ursprung
Commit
9804fd527b
3 geänderte Dateien mit 30 neuen und 1 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 1 1
      rtl/objpas/sysutils/sysstr.inc
  3. 28 0
      tests/webtbs/tw13076.pp

+ 1 - 0
.gitattributes

@@ -12427,6 +12427,7 @@ tests/webtbs/tw12993.pp svneol=native#text/plain
 tests/webtbs/tw13015.pp svneol=native#text/plain
 tests/webtbs/tw13019.pp svneol=native#text/plain
 tests/webtbs/tw13075.pp svneol=native#text/plain
+tests/webtbs/tw13076.pp svneol=native#text/plain
 tests/webtbs/tw1310.pp svneol=native#text/plain
 tests/webtbs/tw13110.pp svneol=native#text/plain
 tests/webtbs/tw13133.pp svneol=native#text/plain

+ 1 - 1
rtl/objpas/sysutils/sysstr.inc

@@ -2277,7 +2277,7 @@ Var
                     end;
                   If thousand And (Digits[N]<>'-') Then
                     Begin
-                    If (DigitExponent Mod 3 = 0) And (DigitExponent>0) Then
+                    If (DigitExponent Mod 3 = 0) And (DigitExponent>0) and (N > 1) Then
                       Begin
                       Buf[0] := FormatSettings.ThousandSeparator;
                       Inc(Buf);

+ 28 - 0
tests/webtbs/tw13076.pp

@@ -0,0 +1,28 @@
+{$ifdef fpc}
+{$mode objfpc}
+{$endif}
+program tw12385;
+
+uses
+  SysUtils;
+
+var
+  s: string;
+  cr: Extended;
+
+Procedure TestIt(CR : Extended; Fmt,Expected : String);
+
+begin
+  S:=FormatFloat(Fmt,cr);
+  If S<>Expected then
+    begin
+    Writeln('"',S,'"<>"',Expected,'" (latter is correct)');
+    Halt(1);
+    end;
+end;
+
+begin
+  DecimalSeparator:='.';
+  ThousandSeparator:=',';
+  TestIt(-10,'###,###,##0.00','-10.00');
+end.