calculator

How to show result with Int on calculator?

假装没事ソ 提交于 2021-01-05 07:25:05
问题 I am making the calculator app. It shows double at the result even when I don't use double. Example) 1+1 = 2.0 But I want like 1+1= 2 Of course, I want to keep double when there is double like 1.2+1.3= 2.5 How should I have to edit? I tried to edit like this, but there is an error. public void equalsOnClick(View view) { Integer result = null; ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino"); try { result = (int)engine.eval(workings); } catch (ScriptException e) { Toast

How do calculators work with precision?

拥有回忆 提交于 2021-01-02 05:48:21
问题 I wonder how calculators work with precision. For example the value of sin(M_PI) is not exactly zero when computed in double precision: #include <math.h> #include <stdio.h> int main() { double x = sin(M_PI); printf("%.20f\n", x); // 0.00000000000000012246 return 0; } Now I would certainly want to print zero when user enters sin(π). I can easily round somewhere on 1e–15 to make this particular case work, but that’s a hack, not a solution. When I start to round like this and the user enters

Is this an efficient calculator in Python?

半世苍凉 提交于 2020-08-10 19:30:07
问题 Is this an efficient calculator in Python? def calculator(): print("\nBasic Calculator.\n") num_1 = input("Enter your first number: ") operation = input("Enter your operation: ") num_2 = input("Enter your second number: ") if operation == ("+"): sum = float(num_1) + float(num_2) print ("The answer is:",(sum)) elif operation == ("-"): sum = float(num_1) - float(num_2) print ("The answer is:",(sum)) elif operation == ("*"): sum = float(num_1) * float(num_2) print ("The answer is:",(sum)) elif

TypeError: '>' not supported between instances of 'list' and 'int'

两盒软妹~` 提交于 2020-05-11 03:50:07
问题 I'm working on a library for calculating certain values in a game. I have this code: million = [1000000, "M"] billion = [million * 1000, "B"] trillion = [billion * 1000, "T"] quadrillion = [trillion * 1000, "Qd"] quintillion = [quadrillion * 1000, "Qn"] sx = [quintillion * 1000, "Sx"] septillion = [sx * 1000, "Sp"] suffixes = [million, billion, trillion, quadrillion, quintillion, sx, septillion] def getSetupResult(orevalue, furnacemultiplier, *upgrades, **kwargs): for i in upgrades: orevalue

how to code a python calculator

你。 提交于 2020-04-17 19:28:39
问题 I want to code a python calculator, but it goes wrong. Okay, I'll show you my code. from time import sleep print('Calculator v1.0 (Python 3.6.2)') ans = input('Hello! Are you here for calculating?(y/n)') if ans == 'y': print('OK! LOADING...') sleep(3) elif ans == 'n': print('Oh, you're not going ahead... OK.') quit() num1 = input('Input 1st number') method = input('Input symbol(+,-,*,/):') num2 = input('Input 2nd number') ans = num1+method+num2 print('Answer is ', ans) And my output....

Calculator without if/else or switch

天大地大妈咪最大 提交于 2020-02-25 06:05:16
问题 I am trying to write calculator for + - * / without conditions. The operator is stored as a string. Is there anyway to achieve it? public class Main { /** * @param args */ public static void main(String[] args) { ////String Operator = ""; String L1=""; String L2=""; String op = "+"; double a = 3; double b = 2; //Operator p = p. Operator p; b = Operator.count(a, op, b); System.out.println(b); } public enum Operator { PLUS("+"), MINUS("-"), DIVIDE("/"), MULTIPLY("*"); private final String

Calculator in C using stack

旧时模样 提交于 2020-02-20 09:15:09
问题 I'm trying to create a calculator in c, which can calculate with priority and get right results for examples like these: ((5+5)/3)*3) -- > 9 ((1+2) * 3) -- > 9 These examples my code below can calculate. But for something like this (2+5) * (2+5) , my program gives wrong answer. I'm using 2 stacks. One for operators and one for numbers. It works on this principle: follows: ((4 - 2) * 5) + 3 --> normal infix expression: + * - 4 2 5 3 Pseudo code: Read + (an operation), push it onto the stack,