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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...