运算符“ *”不能应用于“ double”和“ decimal”类型的操作数 [英] Operator '*' cannot be applied to operands of type 'double' and 'decimal'

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

问题描述

我在程序中收到了此消息,但是我不知道如何解决它,我已经在网上搜索了,但是没有找到任何可以帮助我的东西。

I get this message in my program but i don't know how to fix it i have search on the net but don't find any thing that can help me.

private double Price;
private int Count;
private double Vat;

private const double foodVATRate = 0.12, otherVATRate = 0.25;
private decimal Finalprice;
private decimal Rate;

public void Readinput()
{
    Finalprice = (decimal)(Price * Count);
}

private void cal()
{
    char answer = char.Parse(Console.ReadLine());
    if ((answer == 'y') || (answer == 'Y'))
        Vat = foodVATRate;
    else
        Vat = otherVATRate;

    Rate = Vat * Finalprice;

运算符'*'不能应用于类型为'double'的操作数,而'decimal'是费率=增值税*最终价格;而且我不知道我可以解决这个问题

Operator '*' cannot be applied to operands of type 'double' and 'decimal' is what comes up on Rate = Vat * Finalprice; and i don't know i can fix it

推荐答案

您需要将其中一个强制转换为另一个。我的猜测是,价格和所有增值税率都应为小数点-通常,double不适合处理任何类型的货币价值。

You need to cast one to the other. My guess is that both Price and all of your VAT rates should really be decimal - double isn't (usually) appropriate for dealing with any type of monetary values.

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

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