Skip to content

Commit b4dbda4

Browse files
committed
Revert "Fixing how 'precision' adjusts the exponent if there's digits (#202)"
This reverts commit 1638bd2.
1 parent 3916707 commit b4dbda4

File tree

8 files changed

+28
-68
lines changed

8 files changed

+28
-68
lines changed

dist/filesize.cjs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ function filesize (arg, {
167167
// Zero is now a special case because bytes divide by 1
168168
if (num === 0) {
169169
result[0] = 0;
170-
171-
if (precision > 0) {
172-
result[0] = result[0].toPrecision(precision);
173-
}
174-
175170
u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
176171
} else {
177172
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
@@ -193,17 +188,6 @@ function filesize (arg, {
193188
e++;
194189
}
195190

196-
// Setting optional precision
197-
if (precision > 0) {
198-
result[0] = result[0].toPrecision(precision);
199-
const [ newResult, newExponent ] = result[0].split(E);
200-
result[0] = newResult;
201-
202-
if (newExponent !== undefined) {
203-
e += parseInt(newExponent, 10);
204-
}
205-
}
206-
207191
u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
208192
}
209193

@@ -212,6 +196,12 @@ function filesize (arg, {
212196
result[0] = -result[0];
213197
}
214198

199+
// Setting optional precision
200+
if (precision > 0) {
201+
result[0] = result[0].toPrecision(precision);
202+
result[0] = result[0].split(E)[0];
203+
}
204+
215205
// Applying custom symbol
216206
result[1] = symbols[result[1]] || result[1];
217207

dist/filesize.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ function filesize (arg, {
163163
// Zero is now a special case because bytes divide by 1
164164
if (num === 0) {
165165
result[0] = 0;
166-
167-
if (precision > 0) {
168-
result[0] = result[0].toPrecision(precision);
169-
}
170-
171166
u = result[1] = STRINGS.symbol[standard][bits ? BITS : BYTES][e];
172167
} else {
173168
val = num / (base === 2 ? Math.pow(2, e * 10) : Math.pow(1000, e));
@@ -189,17 +184,6 @@ function filesize (arg, {
189184
e++;
190185
}
191186

192-
// Setting optional precision
193-
if (precision > 0) {
194-
result[0] = result[0].toPrecision(precision);
195-
const [ newResult, newExponent ] = result[0].split(E);
196-
result[0] = newResult;
197-
198-
if (newExponent !== undefined) {
199-
e += parseInt(newExponent, 10);
200-
}
201-
}
202-
203187
u = result[1] = base === 10 && e === 1 ? bits ? SI_KBIT : SI_KBYTE : STRINGS.symbol[standard][bits ? BITS : BYTES][e];
204188
}
205189

@@ -208,6 +192,12 @@ function filesize (arg, {
208192
result[0] = -result[0];
209193
}
210194

195+
// Setting optional precision
196+
if (precision > 0) {
197+
result[0] = result[0].toPrecision(precision);
198+
result[0] = result[0].split(E)[0];
199+
}
200+
211201
// Applying custom symbol
212202
result[1] = symbols[result[1]] || result[1];
213203

dist/filesize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)