Renamed previous Scientific Notation to Engineering Notation and added real Scientific Notation (Issue #110)

This commit is contained in:
Aktanusa
2018-07-12 23:05:18 -04:00
parent b5f6fef9ae
commit 22ae4ebc4c
3 changed files with 44 additions and 20 deletions

View File

@@ -97,17 +97,29 @@ CM.Disp.Beautify = function(num, frac) {
negative = true;
}
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)) {
answer = (Math.floor(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
break;
if (CM.Config.Scale == 4) {
if (num > 9) {
var count = 0;
while (num > 9) {
count++;
num /= 10;
}
answer = Math.round(num * 1000) / 1000 + 'E+' + count;
}
else if (CM.Config.Scale > 1) {
if (num >= Math.pow(1000, i + 2)) {
answer = (Math.floor(num / Math.pow(1000, i + 1)) / 1000) + (CM.Config.Scale == 2 ? (' ' + CM.Disp.shortScale[i]) : ('e+' + ((i + 2) * 3)));
break;
}
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)) {
answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
break;
}
}
else if (CM.Config.Scale > 1) {
if (num >= Math.pow(1000, i + 2)) {
answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + (CM.Config.Scale == 2 ? (' ' + CM.Disp.shortScale[i]) : ('E+' + ((i + 2) * 3)));
break;
}
}
}
}