Comments (4)
Hey I would like to tackle this issue. Do you have more information?
from calculator.
Hey I would like to tackle this issue. Do you have more information?
Sure @arenodi,
before I merged the PR (#18) the percent functionality worked fine but after it, it doesn't work properly.
Example: 100 - 50% = 50
The calculator says 99.5 but it should be 50.
Before I merged #18 this example worked fine and it printed 50
from calculator.
hey @N3v1 , there are a few things to take into consideration:
Lines 73 to 77:
- The
if true
body will never run, because thetypeof
of the argnumber
will always be astring
. - In
else
body, thepercentageToDecimal()
function is called and then...
Lines 48 to 50:
- The
percentageToDecimal()
function receives thestring
and the parses it withnew Decimal()
. new Decimal()
returns a decimal and then the decimal is divided by 100.percentageToDecimal()
then returns the quotient of that operation.
That is, the '50' as a string will trigger the percentageToDecimal()
function that will invoke the new Decimal()
and be divided by 100, and then returned as 0.5
, hence 100 - 0.5 = 99.5
.
Fix:
To fix this problem I made a few changes on the code:
- Add 'math.js' library to parse and evaluate expressions.
- Lines 28-34
- Remove library 'decimal.js'.
- Remove
percentageToDecimal()
function. - Partially refactoring.
- Lines 43-49
Note: With 'math.js' library the expression is compiled from the way it is typed and then evaluated, eliminating the need to custom parsing it. Also the lib is powerful enough to support future features as advanced arithmetics operations.
I will create a pull request on it.
from calculator.
Thank you @arenodi for your work
from calculator.
Related Issues (20)
- ๐ Feature: Adding keyboard input HOT 2
- ๐ก Adapt website for iPhones and other mobile devices HOT 4
- ๐ Security: Fix code scanning alert - Inclusion of functionality from an untrusted source HOT 2
- ๐ก Warning: Error with Premissions-Policy header... HOT 2
- ๐งน UI REVAMP HOT 3
- Fix code scanning alert - Inclusion of functionality from an untrusted source HOT 8
- ๐ก Design: Fix content overlapping HOT 6
- ๐ก Warning: Failed to find a valid digest in the 'integrity' attribute for resource ... HOT 6
- Config Prettier HOT 4
- Power feature doesn't work and throws errors HOT 1
- ๐ด BUG: When there is a missing clothing Parenthesis, the calculation failed HOT 1
- ๐ด BUG: The calculator allows writing arithmetic operator not after a number. So, an error can happen. HOT 5
- ๐ Question: Should we update from CSS to SCSS HOT 3
- Create a new Readme HOT 4
- ๐ด BUG: pressing i | I HOT 1
- ๐ด BUG: F1 -> F12 HOT 4
- ๐ด BUG: Shift + numeric keys
- ๐ด BUG: Pressing enter without calculation HOT 2
- create tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from calculator.