arithmetic operation c#

arithmetic operation c#

k005
Advisor Advisor
2,234 Views
10 Replies
Message 1 of 11

arithmetic operation c#

k005
Advisor
Advisor


54.09 m³
25.32 m³

-5.40 m³

 

How can I get the result of the operation as 74.01?

0 Likes
2,235 Views
10 Replies
Replies (10)
Message 2 of 11

ilovejingle
Enthusiast
Enthusiast

ambiguous question, if you are talking about strings. you need to isolate the number string using a split method, then use double.parse(string) to get the number data. and then do the arithmetic operations.

0 Likes
Message 3 of 11

k005
Advisor
Advisor

Yes string value. i am getting this data with Regex. We are already doing the double parse part. transaction is in progress. But it is not falling cumulatively. is adding

0 Likes
Message 4 of 11

ilovejingle
Enthusiast
Enthusiast

could you please share a short code snippet. otherwise it is very difficult to understand the problem.

Message 5 of 11

k005
Advisor
Advisor

Of course I will share. I'm at work now. I'll write again when I get home tonight.

0 Likes
Message 6 of 11

k005
Advisor
Advisor

@ilovejingle 

 

 foreach (string record in data)
                {
                    if (rgx.IsMatch(record))
                    {
                        foreach (Match m in rgx.Matches(record))
                        {
                            if (m.Groups[1].ToString() != "")
                            {
                                sum1 += double.Parse(m.Groups[1].ToString());
                                
                            }
                            else
                            {
                                //toplam20lik += double.Parse(m.Groups[2].ToString());
                              
                            }
                        }
                    }
                    else
                    {
                     MessageBox.Show("{0} desene uymayan veri", record);
                    }
                }
0 Likes
Message 7 of 11

Norman_Yuan
Mentor
Mentor

If your application has to deal with numerical values that come in as text strings, or mixed with non-numerical text string, it is really, really bad programming practice to mix numerical value calculation with text string manipulating/parsing together, whether you use Regular Expression or not.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 11

k005
Advisor
Advisor

@Norman_Yuan 

 

So how can I get the negative values for group2 according to this situation?

0 Likes
Message 9 of 11

jtoverka
Advocate
Advocate
Message 10 of 11

_gile
Consultant
Consultant

See the Regex in this reply.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 11

k005
Advisor
Advisor

I'll get back to you on both issues... Thank you.

0 Likes