Tips and Frequently Asked Questions
Dealing with floating point number precision in TAdvStringGrid
When wanting to keep floating point numbers with high precision in the grid but display with less precision, the OnGetFloatFormat event can be used. In this code snippet, the grid cell value is set with a floating point number with 8 digits but is displayed with only 3 digits precision. Internally, we can keep calculating with values with 8 digits.
Sample:
// Set float value with full precision begin advstringgrid1.FloatFormat := ''%g''; advstringgrid1.Floats[1,1] := 1.23456789; advstringgrid1.Floats[1,2] := 9.87654321; end; // ensure floating point number is only displayed with 3 digits procedure TForm4.AdvStringGrid1GetFloatFormat(Sender: TObject; ACol, ARow: Integer; var IsFloat: Boolean; var FloatFormat: string); begin FloatFormat := ''%.3f''; end; // do calculation at full precision begin advstringgrid1.Floats[1,3] := advstringgrid1.Floats[1,1] + advstringgrid1.Floats[1,2]; end;
1.235
9.877
but the displayed result is
11.111
as the sum calculated is based on full precision.
Pricing
Single Developer License
Small Team License
Site License
TMS VCL UI Pack
€ 375
€
150
yearly renewal
license for 1 developer
MOST POPULAR
BEST VALUE
All prices excl. VAT. Renewal price is subject to change and only valid up to 30 days after license has expired. After renewal period a discount price is offered to renew the license.
Free Trial
Note that the TMS VCL UI Pack replaces the TMS Component Pack. Both products can't be installed simultaneously. Therefore TMS Component Pack must first be uninstalled before installing the TMS VCL UI Pack