Out write rate into a string - Operator '/' cannot be applied to operands of type 'string' and** > 'double'

后端 未结 2 355
野性不改
野性不改 2021-01-28 22:39

it is such that I must have written price in a string to be displayed to users.

right now will give this error is

Operator \'/\' cannot be

相关标签:
2条回答
  • 2021-01-28 23:23

    prisenMedlemskab seems to be a string, so you cannot divide it for a number. Try to convert as follows

    Double moms = 1.30;
    ButtonPay.Text = "Buy Membership - DKK " + (Convert.ToDouble(prisenMedlemskab) / moms).ToString("F2") + ",- Kr";
    

    By the way is safer to convert prisenMedlemskab before use it directly so you can check if converted value is a legal one (so if prisenMedlemskab has an actual convertable value)

    0 讨论(0)
  • 2021-01-28 23:28

    As far as I can tell you, prisenMedlemskab is a string and not an integer You have to parse it.

    e.g.

    double prisenMedlemskabDouble = double.Parse(prisenMedlemskab);
    

    And then do

    ButtonPay.Text = "Buy Membership - DKK " + (prisenMedlemskabDouble / moms).ToString("F2") + ",- Kr";
    
    0 讨论(0)
提交回复
热议问题