fpspreadsheet: Fix occasional rounding issue (http://www.pilotlogic.com/sitejoom/index.php/forum/pl-fpspreadsheet/3452-number-in-cell-and-formatting)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5244 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
4df9e5dc9b
commit
47a09340ee
@ -215,6 +215,9 @@ function ConvertFloatToStr(AValue: Double; AParams: TsNumFormatParams;
|
||||
AFormatSettings: TFormatSettings): String;
|
||||
function CountDecs(AFormatString: String; ADecChars: TsDecsChars = ['0']): Byte;
|
||||
|
||||
function GeneralFormatFloat(AValue: Double;
|
||||
AFormatSettings: TFormatSettings): String; inline;
|
||||
|
||||
function IsBoolValue(const AText, ATrueText, AFalseText: String;
|
||||
out AValue: Boolean): Boolean;
|
||||
|
||||
@ -802,7 +805,7 @@ begin
|
||||
|
||||
if AParams = nil then
|
||||
begin
|
||||
Result := FloatToStrF(AValue, ffGeneral, 20, 20, fs);
|
||||
Result := GeneralFormatFloat(AValue, fs);
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -827,18 +830,9 @@ begin
|
||||
|
||||
el := 0;
|
||||
while (el < numEl) do begin
|
||||
{
|
||||
if section.Elements[el].Token = nftTextFormat then
|
||||
begin
|
||||
s := FloatToStrF(AValue, ffGeneral, 20, 20, fs);
|
||||
if (sidx=0) and isNeg then s := '-' + s;
|
||||
Result := Result + s;
|
||||
end
|
||||
else
|
||||
}
|
||||
if section.Elements[el].Token = nftGeneral then
|
||||
begin
|
||||
s := FloatToStrF(AValue, ffGeneral, 20, 20, fs);
|
||||
s := GeneralFormatFloat(AValue, fs);
|
||||
if (sidx=0) and isNeg then s := '-' + s;
|
||||
Result := Result + s;
|
||||
end
|
||||
@ -981,6 +975,13 @@ begin
|
||||
end; // while
|
||||
end;
|
||||
|
||||
function GeneralFormatFloat(AValue: Double;
|
||||
AFormatSettings: TFormatSettings): String;
|
||||
begin
|
||||
Result := FloatToStrF(AValue, ffGeneral, 16, 16, AFormatSettings);
|
||||
// 16 is for best rounding results
|
||||
end;
|
||||
|
||||
|
||||
{==============================================================================}
|
||||
{ Utility functions }
|
||||
|
@ -1792,7 +1792,7 @@ begin
|
||||
if IsDateTime(lNumber, nf, nfs, lDateTime) then
|
||||
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
||||
else if nf=nfText then
|
||||
FWorksheet.WriteText(cell, FloatToStrF(lNumber, ffGeneral, 20,20, FWorkbook.FormatSettings))
|
||||
FWorksheet.WriteText(cell, GeneralFormatFloat(lNumber, FWorkbook.FormatSettings))
|
||||
else
|
||||
FWorksheet.WriteNumber(cell, lNumber, nf, nfs);
|
||||
ApplyCellFormatting(cell, XF);
|
||||
@ -1846,7 +1846,7 @@ begin
|
||||
if IsDateTime(value, nf, nfs, dt) then
|
||||
FWorksheet.WriteDateTime(cell, dt, nf, nfs)
|
||||
else if nf = nfText then
|
||||
FWorksheet.WriteText(cell, FloatToStrF(value, ffGeneral, 20, 20, FWorkbook.FormatSettings))
|
||||
FWorksheet.WriteText(cell, GeneralFormatFloat(value, FWorkbook.FormatSettings))
|
||||
else
|
||||
FWorksheet.WriteNumber(cell, value, nf, nfs);
|
||||
|
||||
@ -2059,7 +2059,7 @@ begin
|
||||
if IsDateTime(Number, nf, nfs, lDateTime) then
|
||||
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
||||
else if nf=nfText then
|
||||
FWorksheet.WriteText(cell, FloatToStrF(Number, ffGeneral, 20,20, FWorkbook.FormatSettings))
|
||||
FWorksheet.WriteText(cell, GeneralFormatFloat(Number, FWorkbook.FormatSettings))
|
||||
else
|
||||
FWorksheet.WriteNumber(cell, Number, nf, nfs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user