Fixed Scientific Notation and Engineering Notation to be more correct
This commit is contained in:
40
src/Disp.js
40
src/Disp.js
@@ -97,8 +97,8 @@ CM.Disp.Beautify = function(num, frac) {
|
||||
negative = true;
|
||||
}
|
||||
|
||||
if (CM.Config.Scale == 4) {
|
||||
if (num > 9) {
|
||||
if (CM.Config.Scale == 3) {
|
||||
if (num >= 10) {
|
||||
var count = 0;
|
||||
while (num >= 10) {
|
||||
count++;
|
||||
@@ -106,6 +106,38 @@ CM.Disp.Beautify = function(num, frac) {
|
||||
}
|
||||
answer = Math.round(num * 1000) / 1000 + 'E+' + count;
|
||||
}
|
||||
else if (num < 1 && num != 0) {
|
||||
var count = 0;
|
||||
while (num < 1) {
|
||||
count++;
|
||||
num *= 10;
|
||||
}
|
||||
answer = Math.round(num * 1000) / 1000 + 'E-' + count;
|
||||
}
|
||||
else {
|
||||
answer = Math.round(num * 1000) / 1000 + 'E+0';
|
||||
}
|
||||
}
|
||||
else if (CM.Config.Scale == 4) {
|
||||
if (num >= 1000) {
|
||||
var count = 0;
|
||||
while (num >= 1000) {
|
||||
count++;
|
||||
num /= 1000;
|
||||
}
|
||||
answer = Math.round(num * 1000) / 1000 + 'E+' + (count * 3);
|
||||
}
|
||||
else if (num < 1 && num != 0) {
|
||||
var count = 0;
|
||||
while (num < 1) {
|
||||
count++;
|
||||
num *= 1000;
|
||||
}
|
||||
answer = Math.round(num * 1000) / 1000 + 'E-' + (count * 3);
|
||||
}
|
||||
else {
|
||||
answer = Math.round(num * 1000) / 1000 + 'E+0';
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) {
|
||||
@@ -115,9 +147,9 @@ CM.Disp.Beautify = function(num, frac) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (CM.Config.Scale > 1) {
|
||||
else if (CM.Config.Scale == 2) {
|
||||
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)));
|
||||
answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + ' ' + CM.Disp.shortScale[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user