feat(report): 更新结算报告服务的小数位格式化处理
- 修改注释说明以明确去尾零和固定小数位的展示要求 - 添加浮动利率和预付金利率的固定四位小数格式化功能 - 新增SetFixedExcelText方法用于固定小数位数显示 - 确保百分比数据正确应用四位小数格式化
This commit is contained in:
+19
-1
@@ -322,7 +322,7 @@ namespace YLErp.Modules.ReportModule.SettlementReportModule
|
||||
/// <summary>
|
||||
/// 部分 Office 版本会将可选小数格式(例如 <c>#,##0.##</c>)错误显示为 <c>20,000.</c>。
|
||||
/// 互换估值中的这些列是展示字段,不参与 Excel 公式计算,因此在模板替换完成后写为已格式化文本,
|
||||
/// 既保留去尾零口径,也避免留下孤立的小数点。
|
||||
/// 以遵守各字段的去尾零或固定小数位展示口径,且避免留下孤立的小数点。
|
||||
/// </summary>
|
||||
private static void FormatSwapValuationDisplayCells(IEnumerable<ExcelWorksheet> sheets, IEnumerable<EodSwapPositionResponse> positions)
|
||||
{
|
||||
@@ -343,6 +343,10 @@ namespace YLErp.Modules.ReportModule.SettlementReportModule
|
||||
SetTrimmedExcelText(worksheet.Cells[row, 10], item.PeriodAmount, 2);
|
||||
SetTrimmedExcelText(worksheet.Cells[row, 11], item.DividendAmount, 2);
|
||||
SetTrimmedExcelText(worksheet.Cells[row, 13], item.InitYtm, 4, percent: true);
|
||||
// 浮动利率(绝对)和预付金利率要求固定保留四位小数,不去尾零。
|
||||
// 模板首列为空白占位列,渲染后的工作表会移除该列;最终文件中两列分别为 P、T。
|
||||
SetFixedExcelText(worksheet.Cells[row, 16], item.FloatRateAbs, 4, percent: true);
|
||||
SetFixedExcelText(worksheet.Cells[row, 20], item.OpenMarginRate, 4, percent: true);
|
||||
}
|
||||
|
||||
var totalRow = dataStartRow + positionList.Count;
|
||||
@@ -366,6 +370,20 @@ namespace YLErp.Modules.ReportModule.SettlementReportModule
|
||||
cell.Style.Numberformat.Format = "@";
|
||||
}
|
||||
|
||||
private static void SetFixedExcelText(ExcelRange cell, decimal? value, int decimalPlaces, bool percent = false)
|
||||
{
|
||||
if (!value.HasValue)
|
||||
{
|
||||
cell.Value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var displayValue = percent ? value.Value * 100m : value.Value;
|
||||
var text = displayValue.ToString("F" + decimalPlaces, CultureInfo.InvariantCulture);
|
||||
cell.Value = percent ? text + "%" : text;
|
||||
cell.Style.Numberformat.Format = "@";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 财务状况
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user