hadley/scales — pull request #17 by BrianDiggs (2012-04-18 23:12:39+00:00)
Title: dollar will not use scientific notation and only give 2 or 0 decimals

As it was written, dollar (dollar_format, its generator
function) could give scientific notation for large round
values and could give a single decimal place for numbers
of a certain magnitude. Bot of these have been fixed.
Additionally, documentation has been updated to reflect
when cents are displayed, and the dollar_format function
now takes an argument which controls the threshold
value for displaying cents. Tests specific for dollar
were added.

Examples of old and new behavior are below:

d> x <- c(100, 0.23, 1.456565, 2e3); dollar(x); dollar_new(x)
[1] "$100.00" "$0.23" "$1.46" "$2,000.00"
[1] "$100.00" "$0.23" "$1.46" "$2,000.00"
d> x <- c(1:10 * 10); dollar(x); dollar_new(x)
[1] "$10" "$20" "$30" "$40" "$50" "$60" "$70" "$80" "$90" "$100"
[1] "$10" "$20" "$30" "$40" "$50" "$60" "$70" "$80" "$90" "$100"
d> x <- (1:10 * 10) + 0.01; dollar(x); dollar_new(x)
[1] "$10.01" "$20.01" "$30.01" "$40.01" "$50.01" "$60.01" "$70.01"
[8] "$80.01" "$90.01" "$100.01"
[1] "$10.01" "$20.01" "$30.01" "$40.01" "$50.01" "$60.01" "$70.01"
[8] "$80.01" "$90.01" "$100.01"
d> x <- (1:10 * 10) + 0.001; dollar(x); dollar_new(x)
[1] "$10" "$20" "$30" "$40" "$50" "$60" "$70" "$80" "$90" "$100"
[1] "$10" "$20" "$30" "$40" "$50" "$60" "$70" "$80" "$90" "$100"
d> x <- 10^(1:8); dollar(x); dollar_new(x)
[1] "$1e+01" "$1e+02" "$1e+03" "$1e+04" "$1e+05" "$1e+06" "$1e+07" "$1e+08"
[1] "$10" "$100" "$1,000" "$10,000" "$100,000"
[6] "$1,000,000" "$10,000,000" "$100,000,000"
d> x <- seq(10111.11, 100000, 10111.11); dollar(x); dollar_new(x)
[1] "$10,111.11" "$20,222.22" "$30,333.33" "$40,444.44" "$50,555.55"
[6] "$60,666.66" "$70,777.77" "$80,888.88" "$90,999.99"
[1] "$10,111.11" "$20,222.22" "$30,333.33" "$40,444.44" "$50,555.55"
[6] "$60,666.66" "$70,777.77" "$80,888.88" "$90,999.99"
d> x <- seq(101111.11, 1000000, 101111.11); dollar(x); dollar_new(x)
[1] "$101,111.1" "$202,222.2" "$303,333.3" "$404,444.4" "$505,555.5"
[6] "$606,666.7" "$707,777.8" "$808,888.9" "$910,000.0"
[1] "$101,111" "$202,222" "$303,333" "$404,444" "$505,556" "$606,667" "$707,778"
[8] "$808,889" "$910,000"
d> x <- seq(101111, 1000000, 101111); dollar(x); dollar_new(x)
[1] "$101,111" "$202,222" "$303,333" "$404,444" "$505,555" "$606,666" "$707,777"
[8] "$808,888" "$909,999"
[1] "$101,111" "$202,222" "$303,333" "$404,444" "$505,555" "$606,666" "$707,777"
[8] "$808,888" "$909,999"
d> x <- seq(10111111.11, 100000000, 10111111.11); dollar(x); dollar_new(x)
[1] "$10,111,111" "$20,222,222" "$30,333,333" "$40,444,444" "$50,555,556"
[6] "$60,666,667" "$70,777,778" "$80,888,889" "$91,000,000"
[1] "$10,111,111" "$20,222,222" "$30,333,333" "$40,444,444" "$50,555,556"
[6] "$60,666,667" "$70,777,778" "$80,888,889" "$91,000,000"
d> x <- (1:10) * 100000; dollar(x); dollar_new(x)
[1] "$1e+05" "$2e+05" "$3e+05" "$4e+05" "$5e+05" "$6e+05" "$7e+05" "$8e+05"
[9] "$9e+05" "$1e+06"
[1] "$100,000" "$200,000" "$300,000" "$400,000" "$500,000"
[6] "$600,000" "$700,000" "$800,000" "$900,000" "$1,000,000"
d> x <- ((1:10) * 100000) + 0.01; dollar(x); dollar_new(x)
[1] "$1e+05" "$2e+05" "$3e+05" "$4e+05" "$5e+05" "$6e+05" "$7e+05" "$8e+05"
[9] "$9e+05" "$1e+06"
[1] "$100,000" "$200,000" "$300,000" "$400,000" "$500,000"
[6] "$600,000" "$700,000" "$800,000" "$900,000" "$1,000,000"