PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] How to multiply the number of two labels in C#

 October 17, 2022     c#, integer, label, string     No comments   

Issue

so i have 2 labels. one of them is a fixed number and doesn't change but the other one changes every 5 seconds. Now i want to multiply them automatically and show them in another label as Results.

what should i do? what am i doing wrong?

i tried this code but it says "operator * cannot be applied to string and string".

label1.Text = BTC_A.Text * BTCPrice_Label.Text;

then i tried

double txt1 = Convert.ToDouble(BTC_A.Text);
            double txt2 = Convert.ToDouble(BTCPrice_Label.Text);

            double sum = txt1 * txt2;

            label1.Text = sum.ToString();

but it says "Input string was not in a correct format"


Solution

so the problem was a dollar sign ( $ ) that i put before the numbers.

i just deleted the sign and this is what the code looks like now:

double AA;
           if (!double.TryParse(BTC_A.Text, out AA))
           {
                MessageBox.Show($"Unable to convert the BTC_A \"{BTC_A.Text}\" to a floating point number");
                return;
           }
           double btcA;
           if (!double.TryParse(BTCPrice_Label.Text, out btcA))
           {
                MessageBox.Show($"Unable to convert the price \"{BTCPrice_Label.Text}\" to a floating point number");
                return;
           }
           label1.Text = (AA * btcA).ToString();


Answered By - Oliver
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing