Skip to content

Commit f6c31c2

Browse files
committed
Improve docs for to_ratio_string/3
1 parent a36851f commit f6c31c2

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

lib/cldr/number.ex

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ defmodule Cldr.Number do
743743
end
744744

745745
@doc """
746-
Formats a number as a possibly approximate ratio.
746+
Formats a number as a (possibly approximate) ratio.
747747
748748
`Cldr.Math.float_to_ratio/2` is used to form a ratio that
749749
represents a float number. The representation is intentionally not
@@ -755,6 +755,9 @@ defmodule Cldr.Number do
755755
When formatting, the returned string is composed of the integer
756756
part (if the integer is not zero) and the fractional part.
757757
758+
See [CLDR Rational Numbers](https://www.unicode.org/reports/tr35/dev/tr35-numbers.html#rational-numbers)
759+
for additional information.
760+
758761
### Arguments
759762
760763
* `number` is an integer or float to be formatted. Decimal
@@ -807,6 +810,18 @@ defmodule Cldr.Number do
807810
808811
* `{:error, {exception, reason}}`.
809812
813+
### Notes
814+
815+
The availability of both "Integer with rational pattern" and "Integer with rational super_sub pattern"
816+
is because ome fonts and rendering systems don’t properly handle the fraction slash, and the
817+
user would see something like 51/2 (fifty-one halves) when 5½ is desired.
818+
819+
| Pattern | Format | Usage | Description |
820+
| :---------------------------------------- | :------------- | :------------------------------------------ | :---------- |
821+
| Rational pattern | {0}⁄{1} | All ratios | The format for a rational fraction with arbitrary numerator and denominator; the English pattern uses the Unicode character ‘⁄’ U+2044 FRACTION SLASH which causes composition of fractions such as 22⁄7, when supported properly by rendering systems and fonts. |
822+
| Integer with rational pattern | {0} {1} | prefer: :default | The format for combining an integer with a rational fraction that is composed using the `Rational` pattern; the English pattern uses U+202F NARROW NO-BREAK SPACE (NNBSP) to produce a _non-breaking thin space_. |
823+
| Integer with rational "super sub" pattern | {0}⁠{1} | prefer: :super_sub and prefer: :precomposed | The format for combining an integer with a rational fraction that is composed using the rational pattern; the English pattern uses U+2060 WORD JOINER, a _zero-width no-break space_. |
824+
810825
### Examples
811826
812827
iex> Cldr.Number.to_ratio_string(3.14159, TestBackend.Cldr)
@@ -851,7 +866,7 @@ defmodule Cldr.Number do
851866
end
852867

853868
def to_ratio_string(number, backend, options) when is_number(number) do
854-
Cldr.Number.Formatter.Ratio.to_ratio_string(number, backend, options)
869+
Formatter.Ratio.to_ratio_string(number, backend, options)
855870
end
856871

857872
def to_ratio_string(%Decimal{} = number, backend, options) do
@@ -861,7 +876,7 @@ defmodule Cldr.Number do
861876
end
862877

863878
@doc """
864-
Formats a number as a possibly approximate ratio or raises
879+
Formats a number as a (possibly approximate) ratio or raises
865880
an exception.
866881
867882
`Cldr.Math.float_to_ratio/2` is used to form a ratio that
@@ -926,6 +941,18 @@ defmodule Cldr.Number do
926941
927942
* raises an exception.
928943
944+
### Notes
945+
946+
The availability of both "Integer with rational pattern" and "Integer with rational super_sub pattern"
947+
is because ome fonts and rendering systems don’t properly handle the fraction slash, and the
948+
user would see something like 51/2 (fifty-one halves) when 5½ is desired.
949+
950+
| Pattern | Format | Usage | Description |
951+
| :---------------------------------------- | :------------- | :------------------------------------------ | :---------- |
952+
| Rational pattern | {0}⁄{1} | All ratios | The format for a rational fraction with arbitrary numerator and denominator; the English pattern uses the Unicode character ‘⁄’ U+2044 FRACTION SLASH which causes composition of fractions such as 22⁄7, when supported properly by rendering systems and fonts. |
953+
| Integer with retional pattern | {0} {1} | prefer: :default | The format for combining an integer with a rational fraction that is composed using the `Rational` pattern; the English pattern uses U+202F NARROW NO-BREAK SPACE (NNBSP) to produce a _non-breaking thin space_. |
954+
| Integer with rational "super sub" pattern | {0}⁠{1} | prefer: :super_sub and prefer: :precomposed | The format for combining an integer with a rational fraction that is composed using the rational pattern; the English pattern uses U+2060 WORD JOINER, a _zero-width no-break space_. |
955+
929956
### Examples
930957
931958
iex> Cldr.Number.to_ratio_string!(3.14159, TestBackend.Cldr)

test/doc_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule Cldr.Number.Doc.Test do
1616
doctest Cldr.Number.Formatter.Decimal
1717
doctest Cldr.Number.Formatter.Short
1818
doctest Cldr.Number.Formatter.Currency
19+
doctest Cldr.Number.Formatter.Ratio
1920

2021
doctest TestBackend.Cldr.Number.System
2122
doctest TestBackend.Cldr.Number

0 commit comments

Comments
 (0)