calculator

Input string was not in a correct format in double.Parse

回眸只為那壹抹淺笑 提交于 2019-11-26 22:07:39
问题 I am new to C#. I'm trying to make a calculator, but the following error occurred: Input string was not in a correct format. This is the summary of the code: double num1, num2, result; private void button14_Click(object sender, EventArgs e) { num1 = Convert.ToDouble(textBox1.Text); textBox1.Text = String.Empty; num2 = double.Parse(textBox1.Text); **//ERROR OCCURED HERE** result = num1 - num2; } private void button13_Click(object sender, EventArgs e) { num1 = Convert.ToDouble(textBox1.Text);

Calculator application including keyboard input in java swing

♀尐吖头ヾ 提交于 2019-11-26 22:05:57
问题 I have a calculator application in java swing, which is working properly with mouse click input. Now I want it to read input using keyboard button stroke. I had heard about the glass pane in java tutorial, but i need to know any other simple method to meet the requirement. 回答1: KeyPadPanel is an example that uses Action and Key Bindings for numeric entry. 来源: https://stackoverflow.com/questions/10099686/calculator-application-including-keyboard-input-in-java-swing

How does a simple calculator with parentheses work?

旧城冷巷雨未停 提交于 2019-11-26 19:52:17
问题 I want to learn how calculators work. For example, say we have inputs in infix notation like this: 1 + 2 x 10 - 2 The parser would have to respect common rules in math. In the above example this means: 1 + (2 x 10) - 2 = 19 (rather than 3 x 10 - 2 = 28) And then consider this: 1 + 2 x ((2 / 9) + 7) - 2 Does it involve an Abstract Syntax Tree? A binary tree? How is the order of operations ensured to be mathematically correct? Must I use the shunting-yard algorithm to convert this to postfix

how to calculate distance while walking in android?

余生长醉 提交于 2019-11-26 19:15:27
问题 I am developing a demo for my app, in which there are two buttons named as "START" and "STOP". When user taps on "START" he will start walking. What I want to do is make it so that when users tap "STOP" then the demo will calculate his distance between "START" and "STOP". If the user pressed "START" and pressed "STOP" without taking a single step, then it must show 0km or 0m. I don't have any idea how I should start this; please make a suggestion. 回答1: One way to go about it is using the

How can I solve equations in Python? [closed]

偶尔善良 提交于 2019-11-26 18:08:09
问题 Let's say I have an equation: 2x + 6 = 12 With algebra we can see that x = 3 . How can I make a program in Python that can solve for x ? I'm new to programming, and I looked at eval() and exec() but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python. 回答1: How about SymPy? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself… 回答2: There are

How get total sum from input box values using Javascript?

拥有回忆 提交于 2019-11-26 17:35:14
I am not perfect in Javascript.. I want to show total sum of values entered in qty input boxes in next input box named total without refreshing page. Can anyone will help me to figure it out..? Here is javascript <script type="text/javascript"> var howmanytoadd = 2; var rows; function calc() { var tot = 0; for (var i = 0; i < rows.length; i++) { var linetot = 0; rows[i].getElementsByTagName('input')[howmanytoadd].value = linetot; tot += linetot; } document.getElementById('total').value = tot } onload = function () { rows = document.getElementById('tab').getElementById('qty1'); for (var i = 0;

Decimal to Fraction conversion in Swift

放肆的年华 提交于 2019-11-26 16:46:00
问题 I am building a calculator and want it to automatically convert every decimal into a fraction. So if the user calculates an expression for which the answer is "0.333333...", it would return "1/3". For "0.25" it would return "1/4". Using GCD, as found here (Decimal to fraction conversion), I have figured out how to convert any rational, terminating decimal into a decimal, but this does not work on any decimal that repeats (like .333333). Every other function for this on stack overflow is in

Smart design of a math parser?

时光怂恿深爱的人放手 提交于 2019-11-26 11:09:19
What is the smartest way to design a math parser? What I mean is a function that takes a math string (like: "2 + 3 / 2 + (2 * 5)") and returns the calculated value? I did write one in VB6 ages ago but it ended up being way to bloated and not very portable (or smart for that matter...). General ideas, psuedo code or real code is appreciated. Justin Poliey A pretty good approach would involve two steps. The first step involves converting the expression from infix to postfix (e.g. via Dijkstra's shunting yard ) notation. Once that's done, it's pretty trivial to write a postfix evaluator . I wrote

How get total sum from input box values using Javascript?

旧时模样 提交于 2019-11-26 08:53:15
问题 I am not perfect in Javascript.. I want to show total sum of values entered in qty input boxes in next input box named total without refreshing page. Can anyone will help me to figure it out..? Here is javascript <script type=\"text/javascript\"> var howmanytoadd = 2; var rows; function calc() { var tot = 0; for (var i = 0; i < rows.length; i++) { var linetot = 0; rows[i].getElementsByTagName(\'input\')[howmanytoadd].value = linetot; tot += linetot; } document.getElementById(\'total\').value

C# Math calculator [duplicate]

与世无争的帅哥 提交于 2019-11-26 04:21:59
问题 Possible Duplicates: Is there a string math evaluator in .NET? Converting string expression to Integer Value using C# Best and shortest way to evaluate mathematical expressions c# evaluating string “3*(4+2)” yield int 18 Is there a way to calculate math expressions like (2-3/4*12) in a different way than presented here? http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx 回答1: DataTable has a Compute method that allows you to write this: var