简体   繁体   English

如何将“%符号”分配给十进制值-这样我就可以在Excel工作表中将其导出

[英]How to assign a “% symbol” to decimal value - so that i can export the same in Excel sheet

How to assign a "% Symbol" to decimal value in C#. 如何在C#中为十进制值分配“%符号”。 Here is my code. 这是我的代码。

So my question is, is there any way I can assign a "%" symbol to BRCList[l].TotalDifference.Value . 所以我的问题是,有什么办法可以给BRCList[l].TotalDifference.Value分配一个“%”符号。 BRCList[l].TotalDifference.Value is decimal type from the service side. 从服务端BRCList[l].TotalDifference.Value是十进制类型。

I need to append "%" symbol: 我需要附加“%”符号:

string TotalDifference = string.Empty;
if (Type == "P")
{
    TotalDifference = String.Format("{0:0.##}", BRCList[l].TotalDifference.Value) + "%";
}

You cannot assign an appended character to a base numeric type. 您不能将附加字符分配给基本数字类型。 The only way would be to first convert it to a string like you do in the code above. 唯一的方法是像上面的代码一样首先将其转换为字符串。

The other option would be to box it in a custom struct that knows it's a percentage stored as a decimal. 另一种选择是将其装在一个自定义结构中,该结构知道它是以百分比形式存储的小数。 Then you could override that struct's ToString method to always automatically append the percentage sign, but you'd also probably need to override all the logical and arithmetic operators that decimal normally supports to maintain any sort of compatibility. 然后,您可以覆盖该结构的ToString方法以始终自动附加百分号,但是您可能还需要覆盖十进制通常支持的所有逻辑和算术运算符,以保持任何兼容性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将多个数据集导出到 excel 表 - How can i export multiple dataset to an excel sheet 如何将datagridview单元格格式值导出到excel? - How can I export datagridview cell formatting value to excel? 将DataTable导出到Excel NumberFormat百分比如何删除多余的小数符号C#问题 - Export DataTable to excel NumberFormat Percentage How to remove extra decimal symbol c# issue 如何将导出功能添加到Grid.Mvc,以便可以将当前搜索结果导出到excel? - How do I add an export feature to Grid.Mvc so that I can export the current search results to excel? 为什么我不能用三元运算符为小数分配值? - Why can't I assign a value to a decimal with a ternary operator? 如何将小数点后的值四舍五入到一个精度,以使总位数不超过15? - How can I round a Decimal value upto a precision so that the total number of digits doesnot cross 15? 如何从下一个数据表获取Same Excel工作表的连续性从c#导出到Excel - how to get the continuation of the Same Excel sheet from next datatable Export to Excel from c# 如何将 excel 工作表导出为图像? - How can I export an excel worksheet as image? 如何将数据导出到 Excel 文件 - How can I export data to an Excel file 如何使用 Excel Interop 检索与基于引用另一个 Excel 工作表的公式的 Excel 单元格关联的值? - How can I retrieve the value associated with an Excel Cell that is based on a formula referencing another Excel Sheet using Excel Interop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM