Skip to content

Commit

Permalink
Display exponentiation
Browse files Browse the repository at this point in the history
  • Loading branch information
ethomson committed Sep 22, 2018
1 parent bfe1083 commit ce3b1c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions public/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,9 @@ BUTTON
background-position: -257px 0;
width: 17px;
}

.resultchar.exponent
{
background-position: -274px 0;
width: 25px;
}
Binary file modified public/digits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@
function setValue(n)
{
value = n;
var displayValue = value;

if (displayValue > 99999999) {
displayValue = displayValue.toExponential(4);
} else if (displayValue < -99999999) {
displayValue = displayValue.toExponential(4);
} else if (displayValue > 0 && displayValue < 0.0000001) {
displayValue = displayValue.toExponential(4);
} else if (displayValue < 0 && displayValue > -0.0000001) {
displayValue = displayValue.toExponential(3);
}

var chars = value.toString().split("");
var chars = displayValue.toString().split("");
var html = "";

for (var c of chars) {
if (c == '-') {
html += "<span class=\"resultchar negative\">" + c + "</span>";
} else if (c == '.') {
html += "<span class=\"resultchar decimal\">" + c + "</span>";
} else {
} else if (c == 'e') {
html += "<span class=\"resultchar exponent\">e</span>";
} else if (c != '+') {
html += "<span class=\"resultchar digit" + c + "\">" + c + "</span>";
}
}
Expand Down

0 comments on commit ce3b1c1

Please sign in to comment.