Question

I have:

textbox1.text == 1.4087
textbox2.text == 521.54

It's not hardcoded, I get it from JSON. Anyway, I want to multiply these two numbers.

I use this code:

double curr = 0.0;
double price = 0.0;
double multiply = 0.0;

double.TryParse(textBox1.Text, out curr);
double.TryParse(textBox2.Text, out price);

multiply = curr * price;

textBox3.Text = multiply.ToString();

I also tried with Convert.ToDouble still no luck. I always get 0 in textBox3. Apparently the strings are not recognized as double. But they are. Any ideas? Thanks!

EDIT: From JSON:

{"high": "567.88", "last": "543.95", "timestamp": "1394987785",

I'm using this code to get what i need:

Regex expression = new Regex(@"last"":\s""(?<Identifier>[0-9]+\.[0-9]+)");
      var results = expression.Matches(Cryp);
                foreach (Match match in results)
                {
                    textBox1.Text = match.Groups["Identifier"].Value;
                } 

Any issues here?

Was it helpful?

Solution

Try This:

double.TryParse(textBox1,NumberStyles.AllowDecimalPoint,
                                 CultureInfo.InvariantCulture, out curr);
double.TryParse(textBox2.Text,NumberStyles.AllowDecimalPoint,
                                 CultureInfo.InvariantCulture, out price);
multiply = curr * price;

OTHER TIPS

I would assume one of the TryParse calls fails resulting in it keeping a value of 0 so regardless of what the working one is, you're going to get 0 for a result.

I just wrote up a basic ASP.NET application with three textboxes and then just pasted your code without changing anything into the event handler for a submit button. Manually typing the two numbers you provided gave the correct answer of 734.693398 in TextBox3. Your inputs must be off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top