-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'davinov-currency-prefixes' into merge-70-
(Conflicts: src/formatTypes.js src/locale.js)
- Loading branch information
Showing
19 changed files
with
299 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createPrecisionPrefix } from "./precisionPrefix.js"; | ||
|
||
export default createPrecisionPrefix(0, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import exponent from "./exponent.js"; | ||
|
||
export default function(step, value) { | ||
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step))); | ||
export function createPrecisionPrefix(minimumPrefixOrder, maximumPrefixOrder) { | ||
return function (step, value) { | ||
return Math.max(0, Math.max(minimumPrefixOrder, Math.min(maximumPrefixOrder, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step))); | ||
} | ||
} | ||
|
||
export default createPrecisionPrefix(-8, 8); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var tape = require("tape"), | ||
format = require("../"); | ||
|
||
// For currencies, only 4 prefixes are commonly used: | ||
// thousands (K), millions (M), billions (B) and trillions (T) | ||
|
||
tape("precisionPrefix(step, value) returns zero between 1 and 100 (unit step)", function (test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+0, 1e+0), 0); // 1 | ||
test.equal(format.currencyPrecisionPrefix(1e+0, 1e+1), 0); // 10 | ||
test.equal(format.currencyPrecisionPrefix(1e+0, 1e+2), 0); // 100 | ||
test.end() | ||
}); | ||
|
||
tape("precisionPrefix(step, value) returns zero between 1 and 100 (thousand step)", function (test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+3, 1e+3), 0); // 1K | ||
test.equal(format.currencyPrecisionPrefix(1e+3, 1e+4), 0); // 10K | ||
test.equal(format.currencyPrecisionPrefix(1e+3, 1e+5), 0); // 100K | ||
test.end() | ||
}); | ||
|
||
tape("precisionPrefix(step, value) returns zero between 1 and 100 (million step)", function (test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+6, 1e+6), 0); // 1M | ||
test.equal(format.currencyPrecisionPrefix(1e+6, 1e+7), 0); // 10M | ||
test.equal(format.currencyPrecisionPrefix(1e+6, 1e+8), 0); // 100M | ||
test.end() | ||
}); | ||
|
||
tape("precisionPrefix(step, value) returns zero between 1 and 100 (billion step)", function (test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+9, 1e+9), 0); // 1B | ||
test.equal(format.currencyPrecisionPrefix(1e+9, 1e+10), 0); // 10B | ||
test.equal(format.currencyPrecisionPrefix(1e+9, 1e+11), 0); // 100B | ||
test.end() | ||
}); | ||
|
||
tape("currencyPrecisionPrefix(step, value) returns the expected precision when value is greater than one trillion", function(test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+12, 1e+12), 0); // 1T | ||
test.equal(format.currencyPrecisionPrefix(1e+12, 1e+13), 0); // 10T | ||
test.equal(format.currencyPrecisionPrefix(1e+12, 1e+14), 0); // 100T | ||
test.equal(format.currencyPrecisionPrefix(1e+12, 1e+15), 0); // 1000T | ||
test.equal(format.currencyPrecisionPrefix(1e+11, 1e+15), 1); // 1000.0T | ||
test.end(); | ||
}); | ||
|
||
tape("currencyPrecisionPrefix(step, value) returns the expected precision when value is less than one unit", function(test) { | ||
test.equal(format.currencyPrecisionPrefix(1e+0, 1e+0), 0); // 1 | ||
test.equal(format.currencyPrecisionPrefix(1e-1, 1e-1), 1); // 0.1 | ||
test.equal(format.currencyPrecisionPrefix(1e-2, 1e-2), 2); // 0.01 | ||
test.equal(format.currencyPrecisionPrefix(1e-3, 1e-3), 3); // 0.001 | ||
test.equal(format.currencyPrecisionPrefix(1e-4, 1e-4), 4); // 0.0001 | ||
test.end(); | ||
}); | ||
|
Oops, something went wrong.