Class: Numeric
Class Method Summary collapse
-
.format(number, value_separator = ",", trailing_zeroes = 2, after = 3, decimal_separator = ".") ⇒ Object
Taken from a code snippet by tthorley at codesnippets.joyent.com/posts/show/1812.
Instance Method Summary collapse
Class Method Details
.format(number, value_separator = ",", trailing_zeroes = 2, after = 3, decimal_separator = ".") ⇒ Object
Taken from a code snippet by tthorley at codesnippets.joyent.com/posts/show/1812
116 117 118 119 |
# File 'lib/libaaron.rb', line 116 def self.format(number, value_separator = ",", trailing_zeroes = 2, after = 3, decimal_separator = ".") pre,post = number.to_s.split(".") pre.gsub(/(\d)(?=(\d{#{after}})+$)/, '\0' + value_separator)+(post ? "#{decimal_separator}#{post == "0" ? "0"*trailing_zeroes : post}" : "") end |
Instance Method Details
#billion ⇒ Object
126 127 128 |
# File 'lib/libaaron.rb', line 126 def billion self*1_000_000_000 end |
#million ⇒ Object
123 124 125 |
# File 'lib/libaaron.rb', line 123 def million self*1_000_000 end |
#thousand ⇒ Object
120 121 122 |
# File 'lib/libaaron.rb', line 120 def thousand self*1_000 end |
#trillion ⇒ Object
129 130 131 |
# File 'lib/libaaron.rb', line 129 def trillion self*1_000_000_000_000 end |