运算符*不能应用于类型十进制和双操作数 [英] can not apply operator * to operand of type decimal and double

查看:168
本文介绍了运算符*不能应用于类型十进制和双操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要申请的5.2%的折扣上product.I已经tryed做这样的事情:

Hi I need to apply a discount of 5.2% on a product.I have tryed doing something like this:

decimal BasePrice {get;set;}
decimal Discount = (BasePrice * 5.2) / 100;



不过,Visual Studio中告诉我,这:

But Visual Studio tells me that it :

不能申请运营商'*'类型为小数,双

can not apply operator '*' to operand of type decimal and double

如果是这样的话我怎么能代表这个折扣?

If that is so how can I represent this discount?

推荐答案

使用

decimal Discount = (BasePrice * 5.2m) / 100;



另外, 5.2 将被视为双。

从的 MSDN

如果你想有一个真正的数字文字被视为小数,使用后缀m或M

If you want a numeric real literal to be treated as decimal, use the suffix m or M

这篇关于运算符*不能应用于类型十进制和双操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆