【问题标题】:How to add trailing zero's in a string with c#?如何使用c#在字符串中添加尾随零?
【发布时间】:2014-02-09 12:13:10
【问题描述】:

我有带小数的金额(300.11 和 9801.98),我将它们导出 Excel,一切都很好。

但有时我的金额带有尾随零,我想在导出时保留这些零?例如,当导出到 Excel 时,300.00 变为 300。我怎样才能解决这个问题?

这是导出前的代码。

AmountCCC 是 double 类型。

row.Amount = row.AmountCCC.ToString(CultureInfo.InvariantCulture);

在屏幕截图中查看记录是如何导出的。

【问题讨论】:

  • 此列是否总是需要 2 位精度?
  • 你是怎么用 Excel 写的?

标签: c# excel ssis formatting trailing


【解决方案1】:

你可以使用N2

row.AmountCCC.ToString("N2", CultureInfo.InvariantCulture);

The Numeric ("N") Format Specifier

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 2011-09-16
    • 2016-05-03
    • 1970-01-01
    • 2017-05-30
    相关资源
    最近更新 更多