Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 949 Bytes

2016-02-15-formatting_numbers.md

File metadata and controls

47 lines (37 loc) · 949 Bytes
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

Telephone number

1235551234.to_s(:phone, country_code: 1)  # => +1-123-555-1234

Currency

1234567890.506.to_s(:currency, precision: 3)  # => $1,234,567,890.506

Percentage

1000.to_s(:percentage, delimiter: '.', separator: ',')  # => 1.000,000%

Delimited

12345678.to_s(:delimited, delimiter: ",")  # => 12,345,678

Rounded

111.2345.to_s(:rounded, significant: true)  # => 111

Human size

1234567.to_s(:human_size)  # => 1.18 MB

Human

12345.to_s(:human)  # => "12.3 Thousand"

I hope the above tip will be useful.