Home > Blockchain >  How can I multiply a string in this case?
How can I multiply a string in this case?

Time:03-03

I have a code. In this code I have a label1 with text: "0,5 min", from substring I get "0,5" and now I need to convert it from minutes to milliseconds like 0,5 * 60 * 1000 = 30000. I can't do it because of this error:

Input string was not in a correct format.

How can I do it?

private async void button2_Click(object sender, EventArgs e)
{
    string num = label1.Text.Substring(0, label1.Text.IndexOf(" min"));
    int mul = Convert.ToInt32(num) * 60 * 1000;

    textBox1.Text = $"{num} - {mul}";
    await Task.Delay(mul);
}

CodePudding user response:

You might want to replace , with . Then you can use double.Parse(num); Also you might want to change it from int to double

  • Related