如何显示字符串的第二个值的格式字符串?

How to display format string for a second value of string?

我把两列合为一列,分别是货币和价值(20000美元)。现在我想添加值的格式字符串,所以它会像这样 > 20,000 美元。但是如何在第二个字符串上添加 property.DisplayFormatString

我尝试添加 property.DisplayFormatString = "0,0.00" 但它没有改变格式

settings.Columns.Add(column =>
{
    column.FieldName = "Value";
    column.Caption = "Total";
    var property = column.PropertiesEdit as TextBoxProperties;

    column.SetDataItemTemplateContent(t =>
    {
        Html.DevExpress().Label(
        l => {
              l.Text = String.Format("{0} {1}", 
                  DataBinder.Eval(t.DataItem, "CurrencyCode"), 
                  DataBinder.Eval(t.DataItem, "Value"));
            property.DisplayFormatString = {"0,0.00"}
        }).Render();
    });
});

我预计的输出将是

USD 20,000

但实际输出是

USD 20000

您可以使用格式字符串 "{1:0,0.00}".

string.Format 中应用格式
 l.Text = String.Format("{0} {1:0,0.00}", 
              DataBinder.Eval(t.DataItem, "CurrencyCode"), 
              DataBinder.Eval(t.DataItem, "Value"));

这将显示为20,000.0。如果你想要没有小数点,你可以尝试 "{1:0,0}" 应该显示 20,000.

你应该将货币格式更改为数据库,而不是像这样在 aspx 页面中获取记录

SELECT Name,FORMAT(TotalAmount,'#,###,#0') from TableName

您可以使用 c

这样的货币格式

c 对于 int 货币 2,000

c2 表示小数或浮点数,如 2,000.00

c3 表示小数或浮点数,如 2,000.000

更多详情,可以查看这篇文章link