Skip to content

Commit

Permalink
Fixed notations bugging out #282
Browse files Browse the repository at this point in the history
Fixed notations bugging out #282
  • Loading branch information
DanielNoord authored Nov 30, 2020
2 parents 786ece6 + a11f82f commit c87a9d4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 22 deletions.
44 changes: 33 additions & 11 deletions CookieMonster.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,51 +886,73 @@ CM.Disp.Beautify = function(num, frac) {
}

if (CM.Config.Scale == 3) {
if (num >= 10) {
if (num >= 999999) {
var count = 0;
while (num >= 10) {
count++;
num /= 10;
}
answer = Math.round(num * 1000) / 1000 + 'E+' + count;
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
}
else if (num < 1 && num != 0) {
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 10;
}
answer = Math.round(num * 1000) / 1000 + 'E-' + count;
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
}
else {
answer = Math.round(num * 1000) / 1000 + 'E+0';
answer = CM.Backup.Beautify(num, frac);
}
}
else if (CM.Config.Scale == 4) {
if (num >= 1000) {
if (um >= 999999) {
var count = 0;
while (num >= 1000) {
count++;
num /= 1000;
}
answer = Math.round(num * 1000) / 1000 + 'E+' + (count * 3);
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3);
}
else if (num < 1 && num != 0) {
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 1000;
}
answer = Math.round(num * 1000) / 1000 + 'E-' + (count * 3);
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3);
}
else {
answer = Math.round(num * 1000) / 1000 + 'E+0';
answer = CM.Backup.Beautify(num, frac);
}
}
else {
for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) {
if (i < CM.Disp.metric.length && CM.Config.Scale == 1) {
if (num >= Math.pow(1000, i + 2)) {
// Revert to Scientific Notation from e27
if (Math.log10(num) > 27) {
if (num >= 999999) {
var count = 0;
while (num >= 10) {
count++;
num /= 10;
}
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
}
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 10;
}
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
}
else {
answer = CM.Backup.Beautify(num, frac);
}
}
else if (num >= Math.pow(1000, i + 2)) {
answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
break;
}
Expand Down
44 changes: 33 additions & 11 deletions src/Disp.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,51 +138,73 @@ CM.Disp.Beautify = function(num, frac) {
}

if (CM.Config.Scale == 3) {
if (num >= 10) {
if (num >= 999999) {
var count = 0;
while (num >= 10) {
count++;
num /= 10;
}
answer = Math.round(num * 1000) / 1000 + 'E+' + count;
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
}
else if (num < 1 && num != 0) {
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 10;
}
answer = Math.round(num * 1000) / 1000 + 'E-' + count;
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
}
else {
answer = Math.round(num * 1000) / 1000 + 'E+0';
answer = CM.Backup.Beautify(num, frac);
}
}
else if (CM.Config.Scale == 4) {
if (num >= 1000) {
if (um >= 999999) {
var count = 0;
while (num >= 1000) {
count++;
num /= 1000;
}
answer = Math.round(num * 1000) / 1000 + 'E+' + (count * 3);
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3);
}
else if (num < 1 && num != 0) {
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 1000;
}
answer = Math.round(num * 1000) / 1000 + 'E-' + (count * 3);
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3);
}
else {
answer = Math.round(num * 1000) / 1000 + 'E+0';
answer = CM.Backup.Beautify(num, frac);
}
}
else {
for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) {
if (i < CM.Disp.metric.length && CM.Config.Scale == 1) {
if (num >= Math.pow(1000, i + 2)) {
// Revert to Scientific Notation from e27
if (Math.log10(num) > 27) {
if (num >= 999999) {
var count = 0;
while (num >= 10) {
count++;
num /= 10;
}
answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
}
else if (num < -999999 && num != 0) {
var count = 0;
while (num < 1) {
count++;
num *= 10;
}
answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
}
else {
answer = CM.Backup.Beautify(num, frac);
}
}
else if (num >= Math.pow(1000, i + 2)) {
answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
break;
}
Expand Down

0 comments on commit c87a9d4

Please sign in to comment.