You've already forked lazarus-ccr
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:
@ -215,6 +215,9 @@ function ConvertFloatToStr(AValue: Double; AParams: TsNumFormatParams;
|
|||||||
AFormatSettings: TFormatSettings): String;
|
AFormatSettings: TFormatSettings): String;
|
||||||
function CountDecs(AFormatString: String; ADecChars: TsDecsChars = ['0']): Byte;
|
function CountDecs(AFormatString: String; ADecChars: TsDecsChars = ['0']): Byte;
|
||||||
|
|
||||||
|
function GeneralFormatFloat(AValue: Double;
|
||||||
|
AFormatSettings: TFormatSettings): String; inline;
|
||||||
|
|
||||||
function IsBoolValue(const AText, ATrueText, AFalseText: String;
|
function IsBoolValue(const AText, ATrueText, AFalseText: String;
|
||||||
out AValue: Boolean): Boolean;
|
out AValue: Boolean): Boolean;
|
||||||
|
|
||||||
@ -802,7 +805,7 @@ begin
|
|||||||
|
|
||||||
if AParams = nil then
|
if AParams = nil then
|
||||||
begin
|
begin
|
||||||
Result := FloatToStrF(AValue, ffGeneral, 20, 20, fs);
|
Result := GeneralFormatFloat(AValue, fs);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -827,18 +830,9 @@ begin
|
|||||||
|
|
||||||
el := 0;
|
el := 0;
|
||||||
while (el < numEl) do begin
|
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
|
if section.Elements[el].Token = nftGeneral then
|
||||||
begin
|
begin
|
||||||
s := FloatToStrF(AValue, ffGeneral, 20, 20, fs);
|
s := GeneralFormatFloat(AValue, fs);
|
||||||
if (sidx=0) and isNeg then s := '-' + s;
|
if (sidx=0) and isNeg then s := '-' + s;
|
||||||
Result := Result + s;
|
Result := Result + s;
|
||||||
end
|
end
|
||||||
@ -981,6 +975,13 @@ begin
|
|||||||
end; // while
|
end; // while
|
||||||
end;
|
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 }
|
{ Utility functions }
|
||||||
|
@ -1792,7 +1792,7 @@ begin
|
|||||||
if IsDateTime(lNumber, nf, nfs, lDateTime) then
|
if IsDateTime(lNumber, nf, nfs, lDateTime) then
|
||||||
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
||||||
else if nf=nfText then
|
else if nf=nfText then
|
||||||
FWorksheet.WriteText(cell, FloatToStrF(lNumber, ffGeneral, 20,20, FWorkbook.FormatSettings))
|
FWorksheet.WriteText(cell, GeneralFormatFloat(lNumber, FWorkbook.FormatSettings))
|
||||||
else
|
else
|
||||||
FWorksheet.WriteNumber(cell, lNumber, nf, nfs);
|
FWorksheet.WriteNumber(cell, lNumber, nf, nfs);
|
||||||
ApplyCellFormatting(cell, XF);
|
ApplyCellFormatting(cell, XF);
|
||||||
@ -1846,7 +1846,7 @@ begin
|
|||||||
if IsDateTime(value, nf, nfs, dt) then
|
if IsDateTime(value, nf, nfs, dt) then
|
||||||
FWorksheet.WriteDateTime(cell, dt, nf, nfs)
|
FWorksheet.WriteDateTime(cell, dt, nf, nfs)
|
||||||
else if nf = nfText then
|
else if nf = nfText then
|
||||||
FWorksheet.WriteText(cell, FloatToStrF(value, ffGeneral, 20, 20, FWorkbook.FormatSettings))
|
FWorksheet.WriteText(cell, GeneralFormatFloat(value, FWorkbook.FormatSettings))
|
||||||
else
|
else
|
||||||
FWorksheet.WriteNumber(cell, value, nf, nfs);
|
FWorksheet.WriteNumber(cell, value, nf, nfs);
|
||||||
|
|
||||||
@ -2059,7 +2059,7 @@ begin
|
|||||||
if IsDateTime(Number, nf, nfs, lDateTime) then
|
if IsDateTime(Number, nf, nfs, lDateTime) then
|
||||||
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
FWorksheet.WriteDateTime(cell, lDateTime, nf, nfs)
|
||||||
else if nf=nfText then
|
else if nf=nfText then
|
||||||
FWorksheet.WriteText(cell, FloatToStrF(Number, ffGeneral, 20,20, FWorkbook.FormatSettings))
|
FWorksheet.WriteText(cell, GeneralFormatFloat(Number, FWorkbook.FormatSettings))
|
||||||
else
|
else
|
||||||
FWorksheet.WriteNumber(cell, Number, nf, nfs);
|
FWorksheet.WriteNumber(cell, Number, nf, nfs);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user