title | tip-number | tip-username | tip-username-profile | tip-description |
---|---|---|---|---|
Formatting numbers to different representation. |
4 |
logesh |
We represent numbers in different format and this could be done easily using number of ways listed below. |
Below are list of representations
1235551234.to_s(:phone, country_code: 1) # => +1-123-555-1234
1234567890.506.to_s(:currency, precision: 3) # => $1,234,567,890.506
1000.to_s(:percentage, delimiter: '.', separator: ',') # => 1.000,000%
12345678.to_s(:delimited, delimiter: ",") # => 12,345,678
111.2345.to_s(:rounded, significant: true) # => 111
1234567.to_s(:human_size) # => 1.18 MB
12345.to_s(:human) # => "12.3 Thousand"
I hope the above tip will be useful.