Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我需要对产品应用 5.2% 的折扣。我尝试过这样做:
decimal BasePrice {get;set;} decimal Discount = (BasePrice * 5.2) / 100;
但是 Visual Studio 告诉我它:
不能将运算符“*”应用于十进制和双精度类型的操作数
如果是这样,我怎么能代表这个折扣?
利用
decimal Discount = (BasePrice * 5.2m) / 100;
否则,5.2将被视为双重。
5.2
来自MSDN:
如果要将数字实数文字视为十进制,请使用后缀 m 或 M