diff --git a/components/fpspreadsheet/fpsnumformat.pas b/components/fpspreadsheet/fpsnumformat.pas index c1fa1fab6..c02c5051c 100644 --- a/components/fpspreadsheet/fpsnumformat.pas +++ b/components/fpspreadsheet/fpsnumformat.pas @@ -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 } diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index f4b6d0664..67f0f7245 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -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);