Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Add Number#humanize
Browse files Browse the repository at this point in the history
Add doc for significant
straight-shoota committed Jul 3, 2018

Verified

This commit was signed with the committer’s verified signature. The key has expired.
mjcarroll Michael Carroll
1 parent 3a21391 commit d0c508e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/number.cr
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ struct Number

# SI prefixes used by `#humanize`. Equal to `SI_PREFIXES` but prepends the
# prefix with a space charater.
SI_PREFIXES_PADDED = ->(magnitude : Int32, number : Float64) do
SI_PREFIXES_PADDED = ->(magnitude : Int32, _number : Float64) do
magnitude = Number.prefix_index(magnitude)
{magnitude, (magnitude == 0 ? " " : si_prefix(magnitude))}
end
@@ -266,8 +266,15 @@ struct Number
# By default, SI prefixes are used (see `SI_PREFIXES`).
#
# ```
# 1_200_000_000.humanize # => "1.2G"
# 0.000_000_012.humanize # => "12n"
# 1_200_000_000.humanize # => "1.2G"
# 0.000_000_012.humanize # => "12n"
# ```
#
# If *significant* is `false`, the number of *precision* digits is preserved
# after the decimal separator.
#
# ```
# 1_234.567_890.humanize(precision: 2) # => "1.2k"
# 1_234.567_890.humanize(precision: 2, significant: false) # => "1.23k"
# ```
#
@@ -302,8 +309,15 @@ struct Number
# By default, SI prefixes are used (see `SI_PREFIXES`).
#
# ```
# 1_200_000_000.humanize # => "1.2G"
# 0.000_000_012.humanize # => "12n"
# 1_200_000_000.humanize # => "1.2G"
# 0.000_000_012.humanize # => "12n"
# ```
#
# If *significant* is `false`, the number of *precision* digits is preserved
# after the decimal separator.
#
# ```
# 1_234.567_890.humanize(precision: 2) # => "1.2k"
# 1_234.567_890.humanize(precision: 2, significant: false) # => "1.23k"
# ```
#

0 comments on commit d0c508e

Please sign in to comment.