小编Pro*_*ack的帖子

如何在Xamarin.Android中的小数点后显示2或3个数字?

我有Article具有属性的模型SellPrice。我想在任何使用它的地方都用2小数点后的数字显示。2在小数点分隔符之后,它始终具有数字值,但是price例如2,30在显示为时2,3,我希望显示为2,30。对于Quantity同一Article模型中的属性,发生同样的事情,例如,如果1,1要将其值显示为,我希望在小数点分隔符后显示3个数字1,100。因为SellPrice我尝试了以下方法:

[Column("sell_price")]
[XmlElement(ElementName = "sell_price", Namespace = "http://tempuri.org/DataSet1.xsd")]
[DisplayFormat(DataFormatString = "{0:C}")]
public decimal SellPrice { get; set; }
Run Code Online (Sandbox Code Playgroud)

但是DisplayFormat用红色下划线,并且不允许使用导入其名称空间System.ComponentModel.DataAnnotations。我猜它已经过时了。为了3在小数点分隔符后显示数字,我什至没有发现过时的东西。我发现了很多办法用它来办String.Format,但我使用SellPrice,并Quantity在大量的在我的项目的地方,我不想每次当我使用模型属性来写String.Format......有什么办法来指定例如在模型中作为属性?

.net c# decimal xamarin.android xamarin

1
推荐指数
1
解决办法
860
查看次数

标签 统计

.net ×1

c# ×1

decimal ×1

xamarin ×1

xamarin.android ×1