Created
April 28, 2015 19:49
-
-
Save lorenzoongithub/ff5460d740379d027c7c to your computer and use it in GitHub Desktop.
numeral.js
This file contains hidden or 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
// | |
// numerals.js - a javascript library for formatting and manipulating numbers | |
// | |
// http://numeraljs.com/ | |
// https://github.com/adamwdraper/Numeral-js | |
// | |
// | |
// This work has been derived from | |
// https://github.com/adamwdraper/Numeral-js/blob/master/tests/numeral/format.js | |
// | |
load('https://cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js'); | |
// | |
// numbers | |
// | |
if (numeral(10000).format("0,0.0000") !== "10,000.0000") throw "" | |
if (numeral(10000.23).format("0,0") !== "10,000") throw "" | |
if (numeral(-10000).format("0,0.0") !== "-10,000.0") throw "" | |
if (numeral(10000.1234).format("0.000") !== "10000.123") throw "" | |
if (numeral(10000).format("0[.]00") !== "10000") throw "" | |
if (numeral(10000.1).format("0[.]00") !== "10000.10") throw "" | |
if (numeral(10000.123).format("0[.]00") !== "10000.12") throw "" | |
if (numeral(10000.456).format("0[.]00") !== "10000.46") throw "" | |
if (numeral(10000.001).format("0[.]00") !== "10000") throw "" | |
if (numeral(10000.45).format("0[.]00[0]") !== "10000.45") throw "" | |
if (numeral(10000.456).format("0[.]00[0]") !== "10000.456") throw "" | |
if (numeral(-10000).format("(0,0.0000)") !== "(10,000.0000)") throw "" | |
if (numeral(-12300).format("+0,0.0000") !== "-12,300.0000") throw "" | |
if (numeral(1230).format("+0,0") !== "1,230") throw "" | |
if (numeral(100.78).format("0") !== "101") throw "" | |
if (numeral(100.28).format("0") !== "100") throw "" | |
if (numeral(1.932).format("0.0") !== "1.9") throw "" | |
if (numeral(1.9687).format("0") !== "2") throw "" | |
if (numeral(1.9687).format("0.0") !== "2.0") throw "" | |
if (numeral(-0.23).format(".00") !== "-.23") throw "" | |
if (numeral(-0.23).format("(.00)") !== "(.23)") throw "" | |
if (numeral(0.23).format("0.00000") !== "0.23000") throw "" | |
if (numeral(0.67).format("0.0[0000]") !== "0.67") throw "" | |
if (numeral(2000000000).format("0.0a") !== "2.0b") throw "" | |
if (numeral(1230974).format("0.0a") !== "1.2m") throw "" | |
if (numeral(1460).format("0a") !== "1k") throw "" | |
if (numeral(-104000).format("0 a") !== "-104 k") throw "" | |
if (numeral(1).format("0o") !== "1st") throw "" | |
if (numeral(52).format("0 o") !== "52 nd") throw "" | |
if (numeral(23).format("0o") !== "23rd") throw "" | |
if (numeral(100).format("0o") !== "100th") throw "" | |
// | |
// currency | |
// | |
if (numeral(1000.234).format("$0,0.00") !== "$1,000.23") throw "" | |
if (numeral(1001).format("$ 0,0.[00]") !== "$ 1,001") throw "" | |
if (numeral(1000.234).format("0,0.00 $") !== "1,000.23 $") throw "" | |
if (numeral(-1000.234).format("($0,0)") !== "($1,000)") throw "" | |
if (numeral(-1000.234).format("(0,0$)") !== "(1,000$)") throw "" | |
if (numeral(-1000.234).format("$0.00") !== "-$1000.23") throw "" | |
if (numeral(1230974).format("($0.00 a)") !== "$1.23 m") throw "" | |
if (numeral(-1000.234).format("$ (0,0)") !== "($ 1,000)") throw "" | |
if (numeral(-1000.234).format("$(0,0)") !== "($1,000)") throw "" | |
if (numeral(-1000.234).format("$ (0,0.00)") !== "($ 1,000.23)") throw "" | |
if (numeral(-1000.234).format("$(0,0.00)") !== "($1,000.23)") throw "" | |
if (numeral(-1000.238).format("$(0,0.00)") !== "($1,000.24)") throw "" | |
if (numeral(-1000.234).format("$-0,0") !== "-$1,000") throw "" | |
if (numeral(-1000.234).format("$ -0,0") !== "-$ 1,000") throw "" | |
if (numeral(1000.234).format("$ (0,0)") !== "$ 1,000") throw "" | |
if (numeral(1000.234).format("$(0,0)") !== "$1,000") throw "" | |
if (numeral(1000.234).format("$ (0,0.00)") !== "$ 1,000.23") throw "" | |
if (numeral(1000.234).format("$(0,0.00)") !== "$1,000.23") throw "" | |
if (numeral(1000.238).format("$(0,0.00)") !== "$1,000.24") throw "" | |
if (numeral(1000.234).format("$-0,0)") !== "$1,000") throw "" | |
if (numeral(1000.234).format("$ -0,0") !== "$ 1,000") throw "" | |
// | |
// bytes | |
// | |
if (numeral(100).format("0b") !== "100B") throw "" | |
if (numeral(2048).format("0 b") !== "2 KB") throw "" | |
if (numeral(5242880).format("0b") !== "5MB") throw "" | |
if (numeral(7884486213.632).format("0.[0] b") !== "7.3 GB") throw "" | |
if (numeral(3467479682786.945).format("0.000b") !== "3.154TB") throw "" | |
if (numeral(3325294185295756).format("0b") !== "3PB") throw "" | |
// | |
// percentages | |
// | |
if (numeral(1).format("0%") !== "100%") throw "" | |
if (numeral(0.974878234).format("0.000%") !== "97.488%") throw "" | |
if (numeral(-0.43).format("0 %") !== "-43 %") throw "" | |
if (numeral(0.43).format("(0.00[0]%)") !== "43.00%") throw "" | |
// | |
// times | |
// | |
if (numeral(25).format("00:00:00") !== "0:00:25") throw "" | |
if (numeral(238).format("00:00:00") !== "0:03:58") throw "" | |
if (numeral(63846).format("00:00:00") !== "17:44:06") throw "" | |
// | |
// rounding | |
// | |
if (numeral(2280002).format("0.00a") !== "2.28m") throw "" | |
if (numeral(10000.23).format("0,0") !== "10,000") throw "" | |
if (numeral(1000.234).format("$0,0.00") !== "$1,000.23") throw "" | |
if (numeral(0.974878234).format("0.000%") !== "97.488%") throw "" | |
if (numeral(-0.433).format("0 %") !== "-43 %") throw "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment