Jump to content

UnimDBGrid DisplayFormat for numeric columns


DayTripper

Recommended Posts

  • 2 months later...

Hi

I've found the same issue...

 

The quick way is write  the onGetText event for every field.

 

procedure TForm1.numberFieldGetText(Sender: TField; var Text: string; DisplayText: Boolean);
begin
    text := formatFloat( TNumericField( sender ).DisplayFormat , sender.value );
end;

 

 

But if you have uniDBUtils.pas and you feel brave, you can touch the "numbers" section in the FieldValueToJS function:

    ...

    ftCurrency:
      begin
        if f.InheritsFrom( TNumericField ) and (TNumericField( f ).DisplayFormat<>'') then
            try
                result := '"'+formatFloat( TNumericField( f ).DisplayFormat , f.value )+'"';
            except
                Result := F.Value;
                // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
                Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
            end
        else begin
            Result := F.Value;
            // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
            Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
        end;
      end;
 

Link to comment
Share on other sites

Hello,

 

But if you have uniDBUtils.pas and you feel brave, you can touch the "numbers" section in the FieldValueToJS function:

    ...

    ftCurrency:
      begin
        if f.InheritsFrom( TNumericField ) and (TNumericField( f ).DisplayFormat<>'') then
            try
                result := '"'+formatFloat( TNumericField( f ).DisplayFormat , f.value )+'"';
            except
                Result := F.Value;
                // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
                Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
            end
        else begin
            Result := F.Value;
            // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
            Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
        end;
      end;
 

 

Which editon are you using ?!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...