C#, Operator '*' cannot be applied to operands of type 'double' and 'decimal'

前端 未结 3 1283
天涯浪人
天涯浪人 2020-12-06 17:19

This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don\'s see any reaso

相关标签:
3条回答
  • 2020-12-06 17:52
    .8m instead of .8
    
    0 讨论(0)
  • 2020-12-06 17:52

    You didn't say which line it was, but I'm betting on these two:

    z = (x*y)*(.8 * 1.732050808m);
    

    And:

    z = (1000 * x)/(y * 1.732050808m)* .8;
    

    Note that your .8 does not have the 'm' qualifier. Every other place I see you did supply that.

    0 讨论(0)
  • 2020-12-06 18:05

    In this line here:

    z = (xy)(.8 * 1.732050808m);

    you specify .8 as a literal, but without the 'm' suffix, the literal specifies a double.

    z = (xy)(.8m * 1.732050808m);

    will fix it.

    0 讨论(0)
提交回复
热议问题