Einzelnen Beitrag anzeigen

NicoDE
(Gast)

n/a Beiträge
 
#22

Re: SystemInfo 1.1.0

  Alt 1. Jun 2007, 11:28
Zitat von OregonGhost:
Ich weiß nicht, ob Delphi eine kulturbezogene Darstellung ermöglicht.
Jedenfalls nicht komplett. Ich überlasse es in meinen Tools einer API-Funktion die Zahl benutzergerecht zu formatieren:
Delphi-Quellcode:
function MyFormatUIntA(const ANumber: AnsiString): AnsiString;
var
  NumberFormat: TNumberFmtA;
  GroupingString: AnsiString;
  GroupingChar: AnsiChar;
  Index: Integer;
  ThousandSep: AnsiString;
begin
  // No fractional digits
  NumberFormat.NumDigits := 0;
  // No leading zeroes in decimal fields
  NumberFormat.LeadingZero := 0;
  // LOCALE_SGROUPING to Grouping (e.g. '3;2;0' = 32, '3;1' = 310)
  NumberFormat.Grouping := 0;
  SetLength(GroupingString, 40);
  SetLength(GroupingString, GetLocaleInfoA(LOCALE_USER_DEFAULT,
    LOCALE_SGROUPING, PAnsiChar(GroupingString), Length(GroupingString)) - 1);
  for Index := 1 to Length(GroupingString) do
  begin
    GroupingChar := GroupingString[Index];
    if Odd(Index) then
    begin
      case GroupingChar of
        '0':
          if Index <> Length(GroupingString) then
          begin
            NumberFormat.Grouping := 0;
            Break;
          end;
        '1'..'9':
          NumberFormat.Grouping := NumberFormat.Grouping * 10 +
            Ord(GroupingChar) - Ord('0');
      else
        NumberFormat.Grouping := 0;
        Break;
      end;
    end
    else if GroupingChar <> ';then
    begin
      NumberFormat.Grouping := 0;
      Break;
    end;
  end;
  if (NumberFormat.Grouping <> 0 ) and
    (GroupingString[Length(GroupingString)] <> '0') then
    NumberFormat.Grouping := NumberFormat.Grouping * 10;
  // No decimal separator
  NumberFormat.lpDecimalSep := '';
  // Thousand separator string
  SetLength(ThousandSep, 40);
  SetLength(ThousandSep, GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
    PAnsiChar(ThousandSep), Length(ThousandSep)) - 1);
  NumberFormat.lpThousandSep := PAnsiChar(ThousandSep);
  // Hardcoded negative number mode (-1.1)
  NumberFormat.NegativeOrder := 1;
  // Finally format the number
  SetLength(Result, 40);
  SetLength(Result, GetNumberFormatA(LOCALE_USER_DEFAULT, 0, PAnsiChar(ANumber),
    Addr(NumberFormat), PAnsiChar(Result), Length(Result)) - 1);
  if Result = 'then
    Result := ANumber;
end;
  Mit Zitat antworten Zitat