[英]C# Remove Decimal in Currency Only If No Cents using String.Format
How do I most efficiently remove decimals in a currency using String.Format only if the variable does not contain cents?仅当变量不包含美分时,如何使用 String.Format 最有效地删除货币中的小数?
etc...等等...
I currently have:我目前有:
$"{String.Format("{0:C}", Price)}"
Thank you.谢谢你。
您应该能够通过使用基于值 mod 1 是否等于零的不同格式来做到这一点
Price.ToString(Price % 1 == 0 ? "C0" : "C");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.