mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
_bestPrefix now chooses shortest prefix when prefix values are the same
This commit is contained in:
parent
5e7a584ab1
commit
96aca3a7bb
@ -911,9 +911,12 @@ function factory (type, config, load, typed) {
|
||||
var diff = Math.abs(
|
||||
Math.log(absValue / prefix.value) / Math.LN10 - 1.2);
|
||||
|
||||
if (diff < bestDiff) {
|
||||
bestPrefix = prefix;
|
||||
bestDiff = diff;
|
||||
if (diff < bestDiff
|
||||
|| (diff === bestDiff && prefix.name.length < bestPrefix.name.length)) {
|
||||
// choose the prefix with the smallest diff, or if equal, choose the one
|
||||
// with the shortest name (can happen with SHORTLONG for example)
|
||||
bestPrefix = prefix;
|
||||
bestDiff = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,6 +364,7 @@ describe('unit', function() {
|
||||
assert.equal(new Unit(500 ,'m').toString(), '500 m');
|
||||
assert.equal(new Unit(600 ,'m').toString(), '0.6 km');
|
||||
assert.equal(new Unit(1000 ,'m').toString(), '1 km');
|
||||
assert.equal(new Unit(1000 ,'ohm').toString(), '1 kohm');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user