Skip to content

Commit

Permalink
Fixing case where rounding results in the wrong exponent, fixes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Sep 25, 2019
1 parent 5b362af commit b326ec5
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 71 deletions.
8 changes: 7 additions & 1 deletion lib/filesize.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2019 Jason Mulligan <[email protected]>
* @license BSD-3-Clause
* @version 4.2.0
* @version 4.2.1
*/
(function (global) {
const b = /^(b|B)$/,
Expand Down Expand Up @@ -97,6 +97,12 @@
}

result[0] = Number(val.toFixed(e > 0 ? round : 0));

if (result[0] === ceil && e < 8 && descriptor.exponent === void 0) {
result[0] = 1;
e++;
}

result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];

if (unix) {
Expand Down
6 changes: 3 additions & 3 deletions lib/filesize.es6.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/filesize.es6.min.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @copyright 2019 Jason Mulligan <[email protected]>
* @license BSD-3-Clause
* @version 4.2.0
* @version 4.2.1
*/
(function (global) {
var b = /^(b|B)$/,
Expand Down Expand Up @@ -115,6 +115,12 @@
}

result[0] = Number(val.toFixed(e > 0 ? round : 0));

if (result[0] === ceil && e < 8 && descriptor.exponent === void 0) {
result[0] = 1;
e++;
}

result[1] = base === 10 && e === 1 ? bits ? "kb" : "kB" : symbol[standard][bits ? "bits" : "bytes"][e];

if (unix) {
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/filesize.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b326ec5

Please sign in to comment.