Page 1 of 1
calculate
Posted: 21 Jan 2019 14:04
by Rafi4
hi
I want to create a flow to calculate digits.
example 2+4=6
2×7=14
9-4=5
6÷6=1
how can I calculate above digits using input Dialog number, single choice menu and script? how can I create ? I am not getting success.
from record4
Re: calculate
Posted: 21 Jan 2019 17:28
by Desmanto
Do you want a single input and directly get result? or you want to do some choice for the operator? (+ - x : etc?)
If you can just simply input the whole correct expression, using single line text. Just input the whole calculation at there (example : 2*7), and eval(value) afterward.
Then put x at the notification on screen to show the result.
You can catch the error from the script, add another notif to tell that the input is not valid.
Re: calculate
Posted: 22 Jan 2019 06:46
by Rafi4
hi desmanto
when I calculating 7/3 . it was showing result as 2 only. how can I get result as 2.33.
thanks from record4
Re: calculate
Posted: 22 Jan 2019 18:01
by Desmanto
That is a little complicated. You must know how you to input the calculation. Common division will always result in integer. You must have one of the number involved in division to have decimal. One way is to append '1.0 * ' to the value before calculation.
So the script now become
The x is later eval to
1.0 * 7/3. Which will be
7.0/3 and the result is in floating number. But this will give 2.3333333333333335. You want only the the last 2 decimal. So you will show it up in 2 decimals format.
Code: Select all
x = "{eval('1.0 * ' + value),numberformat,0.00}"
The result now become 2.33
This maybe doesn't cover all situation, but should be good for most cases.