diff --git a/src/number.cr b/src/number.cr index 08716c30c425..d9dfc2fd919d 100644 --- a/src/number.cr +++ b/src/number.cr @@ -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" # ``` #