Browse Source

* sysutils.format: floating point formatting takes care of currency type now

git-svn-id: trunk@736 -
florian 20 years ago
parent
commit
9e6c9d4fc7
3 changed files with 34 additions and 10 deletions
  1. 1 0
      .gitattributes
  2. 20 10
      rtl/objpas/sysutils/sysformt.inc
  3. 13 0
      tests/webtbs/tw4215.pp

+ 1 - 0
.gitattributes

@@ -6151,6 +6151,7 @@ tests/webtbs/tw4173.pp svneol=native#text/plain
 tests/webtbs/tw4188.pp svneol=native#text/plain
 tests/webtbs/tw4199.pp svneol=native#text/plain
 tests/webtbs/tw4202.pp svneol=native#text/plain
+tests/webtbs/tw4215.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

+ 20 - 10
rtl/objpas/sysutils/sysformt.inc

@@ -231,24 +231,34 @@ begin
               ToAdd:=StringOfChar('0',Index)+ToAdd
               end;
         'E' : begin
-              CheckArg(vtExtended,true);
-              ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffexponent,Prec,3);
+              if CheckArg(vtCurrency,false) then
+                ToAdd:=FloatToStrF(Args[doarg].VCurrency^,ffexponent,Prec,3)
+              else if CheckArg(vtExtended,true) then
+                ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffexponent,Prec,3);
               end;
         'F' : begin
-              CheckArg(vtExtended,true);
-              ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffFixed,9999,Prec);
+              if CheckArg(vtCurrency,false) then
+                ToAdd:=FloatToStrF(Args[doarg].VCurrency^,ffFixed,9999,Prec)
+              else if CheckArg(vtExtended,true) then
+                ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffFixed,9999,Prec);
               end;
         'G' : begin
-              CheckArg(vtExtended,true);
-              ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffGeneral,Prec,3);
+              if CheckArg(vtCurrency,false) then
+                ToAdd:=FloatToStrF(Args[doarg].VCurrency^,ffGeneral,Prec,3)
+              else if CheckArg(vtExtended,true) then
+                ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffGeneral,Prec,3);
               end;
         'N' : begin
-              CheckArg(vtExtended,true);
-              ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffNumber,9999,Prec);
+              if CheckArg(vtCurrency,false) then
+                ToAdd:=FloatToStrF(Args[doarg].VCurrency^,ffNumber,9999,Prec)
+              else if CheckArg(vtExtended,true) then
+                ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffNumber,9999,Prec);
               end;
         'M' : begin
-              CheckArg(vtExtended,true);
-              ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffCurrency,9999,Prec);
+              if CheckArg(vtExtended,false) then
+                ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffCurrency,9999,Prec)
+              else if CheckArg(vtCurrency,true) then
+                ToAdd:=FloatToStrF(Args[doarg].VCurrency^,ffCurrency,9999,Prec);
               end;
         'S' : begin
                 if CheckArg(vtString,false) then

+ 13 - 0
tests/webtbs/tw4215.pp

@@ -0,0 +1,13 @@
+{ Source provided for Free Pascal Bug Report 4215 }
+{ Submitted by "Tony Maro" on  2005-07-24 }
+{ e-mail: [email protected] }
+uses
+  sysutils;
+var
+   MyCurrency: Currency;
+begin
+   CurrencyFormat := 0; // optional? It's my default anyway.
+   MyCurrency := 12.53;
+   writeln(MyCurrency); // this works
+   writeln(format('%n',[MyCurrency])); // this doesn't
+end.