Skip to content

Commit

Permalink
decimal point problem fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tamim9 committed Aug 14, 2021
1 parent 5641629 commit 5a1b375
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ function equalFunc() {
if (screen.value != '') {
secondValue = Number(screen.value);

var splitted;
for (let part of firstValue.toString()) {
if (part == '.') {
splitted = firstValue.toString().split('.');
firstValue = firstValue * Math.pow(10, splitted[1].length);
secondValue = secondValue * Math.pow(10, splitted[1].length);
}
}
for (let part of secondValue.toString()) {
if (part == '.') {
splitted = secondValue.toString().split('.');
firstValue = firstValue * Math.pow(10, splitted[1].length);
secondValue = secondValue * Math.pow(10, splitted[1].length);
}
}

var calced = 0;

switch (operator) {
Expand All @@ -271,6 +287,9 @@ function equalFunc() {
break;
}

if (typeof splitted != 'undefined') {
calced = calced / Math.pow(10, splitted[1].length);
}

// prevent answer from overflowing the display
screen.value = preventOverflow(calced);
Expand Down
2 changes: 1 addition & 1 deletion sw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// service worker file
const staticCacheName = 'calculator-v2.1.7';
const staticCacheName = 'calculator-v2.1.8';
const assets = [
'/smart-calculator/',
'/smart-calculator/index.html',
Expand Down

0 comments on commit 5a1b375

Please sign in to comment.