mirror of
https://github.com/plausible/analytics.git
synced 2024-11-24 04:32:57 +03:00
1369 lines
108 KiB
HTML
1369 lines
108 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="generator" content="ExDoc v0.30.3">
|
||
<meta name="project" content="Plausible v0.0.1">
|
||
|
||
<title>Plausible.Cldr.Number — Plausible v0.0.1</title>
|
||
<link rel="stylesheet" href="dist/html-elixir-P5GXSCHE.css" />
|
||
|
||
|
||
<script src="dist/handlebars.runtime-NWIB6V2M.js"></script>
|
||
<script src="dist/handlebars.templates-NBND3S2D.js"></script>
|
||
<script src="dist/sidebar_items-E4F6819C.js"></script>
|
||
|
||
<script src="docs_config.js"></script>
|
||
|
||
<script async src="dist/html-CGDDOCMI.js"></script>
|
||
|
||
|
||
</head>
|
||
<body data-type="modules" class="page-module">
|
||
<script>
|
||
|
||
try {
|
||
var settings = JSON.parse(localStorage.getItem('ex_doc:settings') || '{}');
|
||
|
||
if (settings.theme === 'dark' ||
|
||
((settings.theme === 'system' || settings.theme == null) &&
|
||
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
||
) {
|
||
document.body.classList.add('dark')
|
||
}
|
||
} catch (error) { }
|
||
</script>
|
||
|
||
<div class="main">
|
||
|
||
<button class="sidebar-button sidebar-toggle" aria-label="toggle sidebar">
|
||
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
|
||
</button>
|
||
|
||
<section class="sidebar">
|
||
<form class="sidebar-search" action="search.html">
|
||
<button type="submit" class="search-button" aria-label="Submit Search">
|
||
<i class="ri-search-2-line" aria-hidden="true" title="Submit search"></i>
|
||
</button>
|
||
<button type="button" tabindex="-1" class="search-close-button" aria-label="Cancel Search">
|
||
<i class="ri-close-line ri-lg" aria-hidden="true" title="Cancel search"></i>
|
||
</button>
|
||
<label class="search-label">
|
||
<p class="sr-only">Search</p>
|
||
<input name="q" type="text" class="search-input" placeholder="Search..." aria-label="Input your search terms" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
||
</label>
|
||
</form>
|
||
|
||
<div class="autocomplete">
|
||
<div class="autocomplete-results">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="sidebar-header">
|
||
|
||
<a href="readme.html">
|
||
<img src="assets/logo.png" alt="Plausible" class="sidebar-projectImage">
|
||
</a>
|
||
|
||
<div class="sidebar-projectDetails">
|
||
<a href="readme.html" class="sidebar-projectName" translate="no">
|
||
Plausible
|
||
</a>
|
||
<div class="sidebar-projectVersion" translate="no">
|
||
v0.0.1
|
||
</div>
|
||
</div>
|
||
<ul class="sidebar-listNav">
|
||
<li><a id="extras-list-link" href="#full-list">Pages</a></li>
|
||
|
||
<li><a id="modules-list-link" href="#full-list">Modules</a></li>
|
||
|
||
|
||
<li><a id="tasks-list-link" href="#full-list"><span translate="no">Mix</span> Tasks</a></li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="gradient"></div>
|
||
<ul id="full-list"></ul>
|
||
</section>
|
||
|
||
<section class="content">
|
||
<output role="status" id="toast"></output>
|
||
<div class="content-outer">
|
||
<div id="content" class="content-inner">
|
||
|
||
<h1>
|
||
<button class="icon-action display-settings">
|
||
<i class="ri-settings-3-line"></i>
|
||
<span class="sr-only">Settings</span>
|
||
</button>
|
||
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" title="View Source" class="icon-action" rel="help">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
<span translate="no">Plausible.Cldr.Number</span>
|
||
<small class="app-vsn" translate="no">(Plausible v0.0.1)</small>
|
||
|
||
</h1>
|
||
|
||
|
||
<section id="moduledoc">
|
||
<p>Formats numbers and currencies based upon CLDR's decimal formats specification.</p><p>The format specification is documentated in <a href="http://unicode.org/reports/tr35/tr35-numbers.html#Number_Formats">Unicode TR35</a>.
|
||
There are several classes of formatting including non-scientific, scientific,
|
||
rules based (for spelling and ordinal formats), compact formats that display <code class="inline">1k</code>
|
||
rather than <code class="inline">1,000</code> and so on. See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.html#to_string/2"><code class="inline">Cldr.Number.to_string/2</code></a> for specific formatting
|
||
options.</p><h3 id="module-non-scientific-notation-formatting" class="section-heading">
|
||
<a href="#module-non-scientific-notation-formatting">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Non-Scientific Notation Formatting
|
||
</a>
|
||
</h3>
|
||
<p>The following description applies to formats that do not use scientific
|
||
notation or significant digits:</p><ul><li><p>If the number of actual integer digits exceeds the maximum integer digits,
|
||
then only the least significant digits are shown. For example, 1997 is
|
||
formatted as "97" if the maximum integer digits is set to 2.</p></li><li><p>If the number of actual integer digits is less than the minimum integer
|
||
digits, then leading zeros are added. For example, 1997 is formatted as
|
||
"01997" if the minimum integer digits is set to 5.</p></li><li><p>If the number of actual fraction digits exceeds the maximum fraction
|
||
digits, then half-even rounding it performed to the maximum fraction
|
||
digits. For example, 0.125 is formatted as "0.12" if the maximum fraction
|
||
digits is 2. This behavior can be changed by specifying a rounding
|
||
increment and a rounding mode.</p></li><li><p>If the number of actual fraction digits is less than the minimum fraction
|
||
digits, then trailing zeros are added. For example, 0.125 is formatted as
|
||
"0.1250" if the minimum fraction digits is set to 4.</p></li><li><p>Trailing fractional zeros are not displayed if they occur j positions after
|
||
the decimal, where j is less than the maximum fraction digits. For example,
|
||
0.10004 is formatted as "0.1" if the maximum fraction digits is four or
|
||
less.</p></li></ul><h3 id="module-scientific-notation-formatting" class="section-heading">
|
||
<a href="#module-scientific-notation-formatting">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Scientific Notation Formatting
|
||
</a>
|
||
</h3>
|
||
<p>Numbers in scientific notation are expressed as the product of a mantissa and
|
||
a power of ten, for example, 1234 can be expressed as 1.234 x 10^3. The
|
||
mantissa is typically in the half-open interval [1.0, 10.0) or sometimes
|
||
[0.0, 1.0), but it need not be. In a pattern, the exponent character
|
||
immediately followed by one or more digit characters indicates scientific
|
||
notation. Example: "0.###E0" formats the number 1234 as "1.234E3".</p><ul><li><p>The number of digit characters after the exponent character gives the
|
||
minimum exponent digit count. There is no maximum. Negative exponents are
|
||
formatted using the localized minus sign, not the prefix and suffix from
|
||
the pattern. This allows patterns such as "0.###E0 m/s". To prefix positive
|
||
exponents with a localized plus sign, specify '+' between the exponent and
|
||
the digits: "0.###E+0" will produce formats "1E+1", "1E+0", "1E-1", and so
|
||
on. (In localized patterns, use the localized plus sign rather than '+'.)</p></li><li><p>The minimum number of integer digits is achieved by adjusting the exponent.
|
||
Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This only
|
||
happens if there is no maximum number of integer digits. If there is a
|
||
maximum, then the minimum number of integer digits is fixed at one.</p></li><li><p>The maximum number of integer digits, if present, specifies the exponent
|
||
grouping. The most common use of this is to generate engineering notation,
|
||
in which the exponent is a multiple of three, for example, "##0.###E0". The
|
||
number 12345 is formatted using "##0.####E0" as "12.345E3".</p></li><li><p>When using scientific notation, the formatter controls the digit counts
|
||
using significant digits logic. The maximum number of significant digits
|
||
limits the total number of integer and fraction digits that will be shown
|
||
in the mantissa; it does not affect parsing. For example, 12345 formatted
|
||
with "##0.##E0" is "12.3E3". Exponential patterns may not contain grouping
|
||
separators.</p></li></ul><h3 id="module-significant-digits" class="section-heading">
|
||
<a href="#module-significant-digits">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Significant Digits
|
||
</a>
|
||
</h3>
|
||
<p>There are two ways of controlling how many digits are shows: (a)
|
||
significant digits counts, or (b) integer and fraction digit counts. Integer
|
||
and fraction digit counts are described above. When a formatter is using
|
||
significant digits counts, it uses however many integer and fraction digits
|
||
are required to display the specified number of significant digits. It may
|
||
ignore min/max integer/fraction digits, or it may use them to the extent
|
||
possible.</p>
|
||
</section>
|
||
|
||
|
||
<section id="summary" class="details-list">
|
||
<h1 class="section-heading">
|
||
<a class="hover-link" href="#summary">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Summary
|
||
</a>
|
||
</h1>
|
||
<div class="summary-functions summary">
|
||
<h2>
|
||
<a href="#functions">Functions</a>
|
||
</h2>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#parse/2" translate="no">parse(string, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Parse a string locale-aware manner and return
|
||
a number.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#resolve_currencies/2" translate="no">resolve_currencies(list, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Resolve curencies from strings within
|
||
a list.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#resolve_currency/2" translate="no">resolve_currency(string, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Resolve a currency from a string</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#resolve_per/2" translate="no">resolve_per(string, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Resolve and tokenize percent or permille
|
||
from the beginning and/or the end of a string</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#resolve_pers/2" translate="no">resolve_pers(list, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Resolve and tokenize percent and permille
|
||
sybols from strings within a list.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#scan/2" translate="no">scan(string, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Scans a string locale-aware manner and returns
|
||
a list of strings and numbers.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_approx_string/2" translate="no">to_approx_string(number, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Formats a number and applies the <code class="inline">:approximately</code> format for
|
||
a locale and number system.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_at_least_string/2" translate="no">to_at_least_string(number, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Formats a number and applies the <code class="inline">:at_least</code> format for
|
||
a locale and number system.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_at_most_string/2" translate="no">to_at_most_string(number, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Formats a number and applies the <code class="inline">:at_most</code> format for
|
||
a locale and number system.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_range_string/2" translate="no">to_range_string(range, options \\ [])</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Formats the first and last numbers of a range and applies
|
||
the <code class="inline">:range</code> format for a locale and number system.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_string/2" translate="no">to_string(number, options \\ default_options())</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Returns a number formatted into a string according to a format pattern and options.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#to_string!/2" translate="no">to_string!(number, options \\ default_options())</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Same as the execution of <a href="#to_string/2"><code class="inline">to_string/2</code></a> but raises an exception if an error would be
|
||
returned.</p></div>
|
||
|
||
</div>
|
||
|
||
<div class="summary-row">
|
||
<div class="summary-signature">
|
||
<a href="#validate_number_system/2" translate="no">validate_number_system(locale, number_system)</a>
|
||
|
||
</div>
|
||
|
||
<div class="summary-synopsis"><p>Return a valid number system from a provided locale and number
|
||
system name or type.</p></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</section>
|
||
|
||
|
||
<section id="functions" class="details-list">
|
||
<h1 class="section-heading">
|
||
<a class="hover-link" href="#functions">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Functions
|
||
</a>
|
||
</h1>
|
||
<div class="functions-list">
|
||
<section class="detail" id="parse/2">
|
||
|
||
<span id="parse/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#parse/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">parse(string, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<p>Parse a string locale-aware manner and return
|
||
a number.</p><h2 id="parse/2-arguments" class="section-heading">
|
||
<a href="#parse/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">string</code> is any <code class="inline">String.t</code></p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="parse/2-options" class="section-heading">
|
||
<a href="#parse/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">:number</code> is one of <code class="inline">:integer</code>, <code class="inline">:float</code>,
|
||
<code class="inline">:decimal</code> or <code class="inline">nil</code>. The default is <code class="inline">nil</code>
|
||
meaning that the type auto-detected as either
|
||
an <code class="inline">integer</code> or a <code class="inline">float</code>.</p></li><li><p><code class="inline">:locale</code> is any locale returned by
|
||
<a href="Plausible.Cldr.html#known_locale_names/0"><code class="inline">Plausible.Cldr.known_locale_names/0</code></a>
|
||
or a <code class="inline">Cldr.LanguageTag.t</code>. The default is
|
||
<a href="Plausible.Cldr.html#get_locale/0"><code class="inline">Plausible.Cldr.get_locale/0</code></a>.</p></li></ul><h2 id="parse/2-returns" class="section-heading">
|
||
<a href="#parse/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li><p>A number of the requested or default type or</p></li><li><p><code class="inline">{:error, {exception, error}}</code> if no number could be determined</p></li></ul><h2 id="parse/2-notes" class="section-heading">
|
||
<a href="#parse/2-notes">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Notes
|
||
</a>
|
||
</h2>
|
||
<p>This function parses a string to return a number but
|
||
in a locale-aware manner. It will normalise grouping
|
||
characters and decimal separators, different forms of
|
||
the <code class="inline">+</code> and <code class="inline">-</code> symbols that appear in Unicode and
|
||
strips any <code class="inline">_</code> characters that might be used for
|
||
formatting in a string. It then parses the number
|
||
using the Elixir standard library functions.</p><h2 id="parse/2-examples" class="section-heading">
|
||
<a href="#parse/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">parse</span><span class="p" data-group-id="4026601729-1">(</span><span class="s">"+1.000,34"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"de"</span><span class="p" data-group-id="4026601729-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4026601729-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="mf">1000.34</span><span class="p" data-group-id="4026601729-2">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">parse</span><span class="p" data-group-id="4026601729-3">(</span><span class="s">"-1_000_000.34"</span><span class="p" data-group-id="4026601729-3">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4026601729-4">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mf">1000000.34</span><span class="p" data-group-id="4026601729-4">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">parse</span><span class="p" data-group-id="4026601729-5">(</span><span class="s">"1.000"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"de"</span><span class="p">,</span><span class="w"> </span><span class="ss">number</span><span class="p">:</span><span class="w"> </span><span class="ss">:integer</span><span class="p" data-group-id="4026601729-5">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4026601729-6">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="mi">1000</span><span class="p" data-group-id="4026601729-6">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">parse</span><span class="p" data-group-id="4026601729-7">(</span><span class="s">"+1.000,34"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"de"</span><span class="p">,</span><span class="w"> </span><span class="ss">number</span><span class="p">:</span><span class="w"> </span><span class="ss">:integer</span><span class="p" data-group-id="4026601729-7">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4026601729-8">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
|
||
</span><span class="p" data-group-id="4026601729-9">{</span><span class="nc">Cldr.Number.ParseError</span><span class="p">,</span><span class="w">
|
||
</span><span class="s">"The string </span><span class="se">\"</span><span class="s">+1.000,34</span><span class="se">\"</span><span class="s"> could not be parsed as a number"</span><span class="p" data-group-id="4026601729-9">}</span><span class="p" data-group-id="4026601729-8">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="resolve_currencies/2">
|
||
|
||
<span id="resolve_currencies/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#resolve_currencies/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">resolve_currencies(list, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<p>Resolve curencies from strings within
|
||
a list.</p><h2 id="resolve_currencies/2-arguments" class="section-heading">
|
||
<a href="#resolve_currencies/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">list</code> is any list in which currency
|
||
names and symbols are expected</p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="resolve_currencies/2-options" class="section-heading">
|
||
<a href="#resolve_currencies/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">:locale</code> is any valid locale returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html"><code class="inline">Cldr.LanguageTag</code></a> struct returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new!/2"><code class="inline">Cldr.Locale.new!/2</code></a>
|
||
The default is <code class="inline">Plausible.Cldr.get_locale()</code></p></li><li><p><code class="inline">:only</code> is an <code class="inline">atom</code> or list of <code class="inline">atoms</code> representing the
|
||
currencies or currency types to be considered for a match.
|
||
The equates to a list of acceptable currencies for parsing.
|
||
See the notes below for currency types.</p></li><li><p><code class="inline">:except</code> is an <code class="inline">atom</code> or list of <code class="inline">atoms</code> representing the
|
||
currencies or currency types to be not considered for a match.
|
||
This equates to a list of unacceptable currencies for parsing.
|
||
See the notes below for currency types.</p></li><li><p><code class="inline">:fuzzy</code> is a float greater than <code class="inline">0.0</code> and less than or
|
||
equal to <code class="inline">1.0</code> which is used as input to
|
||
<a href="https://hexdocs.pm/elixir/String.html#jaro_distance/2"><code class="inline">String.jaro_distance/2</code></a> to determine is the provided
|
||
currency string is <em>close enough</em> to a known currency
|
||
string for it to identify definitively a currency code.
|
||
It is recommended to use numbers greater than <code class="inline">0.8</code> in
|
||
order to reduce false positives.</p></li></ul><h2 id="resolve_currencies/2-notes" class="section-heading">
|
||
<a href="#resolve_currencies/2-notes">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Notes
|
||
</a>
|
||
</h2>
|
||
<p>The <code class="inline">:only</code> and <code class="inline">:except</code> options accept a list of
|
||
currency codes and/or currency types. The following
|
||
types are recognised.</p><p>If both <code class="inline">:only</code> and <code class="inline">:except</code> are specified,
|
||
the <code class="inline">:except</code> entries take priority - that means
|
||
any entries in <code class="inline">:except</code> are removed from the <code class="inline">:only</code>
|
||
entries.</p><ul><li><p><code class="inline">:all</code>, the default, considers all currencies</p></li><li><p><code class="inline">:current</code> considers those currencies that have a <code class="inline">:to</code>
|
||
date of nil and which also is a known ISO4217 currency</p></li><li><p><code class="inline">:historic</code> is the opposite of <code class="inline">:current</code></p></li><li><p><code class="inline">:tender</code> considers currencies that are legal tender</p></li><li><p><code class="inline">:unannotated</code> considers currencies that don't have
|
||
"(some string)" in their names. These are usually
|
||
financial instruments.</p></li></ul><h2 id="resolve_currencies/2-examples" class="section-heading">
|
||
<a href="#resolve_currencies/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7870550924-1">(</span><span class="s">"100 US dollars"</span><span class="p" data-group-id="7870550924-1">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="o">|></span><span class="w"> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currencies</span><span class="w">
|
||
</span><span class="p" data-group-id="7870550924-2">[</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">:USD</span><span class="p" data-group-id="7870550924-2">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7870550924-3">(</span><span class="s">"100 eurosports"</span><span class="p" data-group-id="7870550924-3">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="o">|></span><span class="w"> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currencies</span><span class="p" data-group-id="7870550924-4">(</span><span class="ss">fuzzy</span><span class="p">:</span><span class="w"> </span><span class="mf">0.75</span><span class="p" data-group-id="7870550924-4">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7870550924-5">[</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">:EUR</span><span class="p" data-group-id="7870550924-5">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7870550924-6">(</span><span class="s">"100 dollars des États-Unis"</span><span class="p" data-group-id="7870550924-6">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="o">|></span><span class="w"> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currencies</span><span class="p" data-group-id="7870550924-7">(</span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="p" data-group-id="7870550924-7">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7870550924-8">[</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">:USD</span><span class="p" data-group-id="7870550924-8">]</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="resolve_currency/2">
|
||
|
||
<span id="resolve_currency/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#resolve_currency/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">resolve_currency(string, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<p>Resolve a currency from a string</p><h2 id="resolve_currency/2-arguments" class="section-heading">
|
||
<a href="#resolve_currency/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">list</code> is any list in which currency
|
||
names and symbols are expected</p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="resolve_currency/2-options" class="section-heading">
|
||
<a href="#resolve_currency/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">:locale</code> is any valid locale returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html"><code class="inline">Cldr.LanguageTag</code></a> struct returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new!/2"><code class="inline">Cldr.Locale.new!/2</code></a>
|
||
The default is <code class="inline">Plausible.Cldr.get_locale()</code></p></li><li><p><code class="inline">:only</code> is an <code class="inline">atom</code> or list of <code class="inline">atoms</code> representing the
|
||
currencies or currency types to be considered for a match.
|
||
The equates to a list of acceptable currencies for parsing.
|
||
See the notes below for currency types.</p></li><li><p><code class="inline">:except</code> is an <code class="inline">atom</code> or list of <code class="inline">atoms</code> representing the
|
||
currencies or currency types to be not considered for a match.
|
||
This equates to a list of unacceptable currencies for parsing.
|
||
See the notes below for currency types.</p></li><li><p><code class="inline">:fuzzy</code> is a float greater than <code class="inline">0.0</code> and less than or
|
||
equal to <code class="inline">1.0</code> which is used as input to
|
||
<a href="https://hexdocs.pm/elixir/String.html#jaro_distance/2"><code class="inline">String.jaro_distance/2</code></a> to determine is the provided
|
||
currency string is <em>close enough</em> to a known currency
|
||
string for it to identify definitively a currency code.
|
||
It is recommended to use numbers greater than <code class="inline">0.8</code> in
|
||
order to reduce false positives.</p></li></ul><h2 id="resolve_currency/2-returns" class="section-heading">
|
||
<a href="#resolve_currency/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li><p>An ISO4217 currency code as an atom or</p></li><li><p><code class="inline">{:error, {exception, message}}</code></p></li></ul><h2 id="resolve_currency/2-notes" class="section-heading">
|
||
<a href="#resolve_currency/2-notes">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Notes
|
||
</a>
|
||
</h2>
|
||
<p>The <code class="inline">:only</code> and <code class="inline">:except</code> options accept a list of
|
||
currency codes and/or currency types. The following
|
||
types are recognised.</p><p>If both <code class="inline">:only</code> and <code class="inline">:except</code> are specified,
|
||
the <code class="inline">:except</code> entries take priority - that means
|
||
any entries in <code class="inline">:except</code> are removed from the <code class="inline">:only</code>
|
||
entries.</p><ul><li><p><code class="inline">:all</code>, the default, considers all currencies</p></li><li><p><code class="inline">:current</code> considers those currencies that have a <code class="inline">:to</code>
|
||
date of nil and which also is a known ISO4217 currency</p></li><li><p><code class="inline">:historic</code> is the opposite of <code class="inline">:current</code></p></li><li><p><code class="inline">:tender</code> considers currencies that are legal tender</p></li><li><p><code class="inline">:unannotated</code> considers currencies that don't have
|
||
"(some string)" in their names. These are usually
|
||
financial instruments.</p></li></ul><h2 id="resolve_currency/2-examples" class="section-heading">
|
||
<a href="#resolve_currency/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currency</span><span class="p" data-group-id="4245260005-1">(</span><span class="s">"US dollars"</span><span class="p" data-group-id="4245260005-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4245260005-2">[</span><span class="ss">:USD</span><span class="p" data-group-id="4245260005-2">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currency</span><span class="p" data-group-id="4245260005-3">(</span><span class="s">"100 eurosports"</span><span class="p">,</span><span class="w"> </span><span class="ss">fuzzy</span><span class="p">:</span><span class="w"> </span><span class="mf">0.75</span><span class="p" data-group-id="4245260005-3">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4245260005-4">[</span><span class="ss">:EUR</span><span class="p" data-group-id="4245260005-4">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currency</span><span class="p" data-group-id="4245260005-5">(</span><span class="s">"dollars des États-Unis"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="p" data-group-id="4245260005-5">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4245260005-6">[</span><span class="ss">:USD</span><span class="p" data-group-id="4245260005-6">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_currency</span><span class="p" data-group-id="4245260005-7">(</span><span class="s">"not a known currency"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="p" data-group-id="4245260005-7">)</span><span class="w">
|
||
</span><span class="p" data-group-id="4245260005-8">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
|
||
</span><span class="p" data-group-id="4245260005-9">{</span><span class="nc">Cldr.UnknownCurrencyError</span><span class="p">,</span><span class="w">
|
||
</span><span class="s">"The currency </span><span class="se">\"</span><span class="s">not a known currency</span><span class="se">\"</span><span class="s"> is unknown or not supported"</span><span class="p" data-group-id="4245260005-9">}</span><span class="p" data-group-id="4245260005-8">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="resolve_per/2">
|
||
|
||
<span id="resolve_per/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#resolve_per/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">resolve_per(string, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
<span class="note">(since 2.22.0)</span>
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> resolve_per(<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>()) ::
|
||
<a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Parser.html#t:per/0">Cldr.Number.Parser.per</a>()
|
||
| [<a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Parser.html#t:per/0">Cldr.Number.Parser.per</a>() | <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()]
|
||
| {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Resolve and tokenize percent or permille
|
||
from the beginning and/or the end of a string</p><h2 id="resolve_per/2-arguments" class="section-heading">
|
||
<a href="#resolve_per/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">list</code> is any list in which percent
|
||
and permille symbols are expected</p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="resolve_per/2-options" class="section-heading">
|
||
<a href="#resolve_per/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><code class="inline">:locale</code> is any valid locale returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html"><code class="inline">Cldr.LanguageTag</code></a> struct returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new!/2"><code class="inline">Cldr.Locale.new!/2</code></a>
|
||
The default is <code class="inline">options[:backend].get_locale()</code></li></ul><h2 id="resolve_per/2-returns" class="section-heading">
|
||
<a href="#resolve_per/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li><p>An <code class="inline">:percent</code> or <code class="inline">permille</code> or</p></li><li><p><code class="inline">{:error, {exception, message}}</code></p></li></ul><h2 id="resolve_per/2-examples" class="section-heading">
|
||
<a href="#resolve_per/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_per</span><span class="w"> </span><span class="s">"11%"</span><span class="w">
|
||
</span><span class="p" data-group-id="8602857597-1">[</span><span class="s">"11"</span><span class="p">,</span><span class="w"> </span><span class="ss">:percent</span><span class="p" data-group-id="8602857597-1">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_per</span><span class="w"> </span><span class="s">"% of linguists"</span><span class="w">
|
||
</span><span class="p" data-group-id="8602857597-2">[</span><span class="ss">:percent</span><span class="p">,</span><span class="w"> </span><span class="s">" of linguists"</span><span class="p" data-group-id="8602857597-2">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_per</span><span class="w"> </span><span class="s">"% of linguists %"</span><span class="w">
|
||
</span><span class="p" data-group-id="8602857597-3">[</span><span class="ss">:percent</span><span class="p">,</span><span class="w"> </span><span class="s">" of linguists "</span><span class="p">,</span><span class="w"> </span><span class="ss">:percent</span><span class="p" data-group-id="8602857597-3">]</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="resolve_pers/2">
|
||
|
||
<span id="resolve_pers/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#resolve_pers/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">resolve_pers(list, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
<span class="note">(since 2.22.0)</span>
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> resolve_pers([<a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(), ...], <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>()) :: [
|
||
<a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Parser.html#t:per/0">Cldr.Number.Parser.per</a>() | <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()
|
||
]</pre>
|
||
|
||
</div>
|
||
|
||
<p>Resolve and tokenize percent and permille
|
||
sybols from strings within a list.</p><p>Percent and permille symbols can be identified
|
||
at the beginning and/or the end of a string.</p><h2 id="resolve_pers/2-arguments" class="section-heading">
|
||
<a href="#resolve_pers/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">list</code> is any list in which percent and
|
||
permille symbols are expected</p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="resolve_pers/2-options" class="section-heading">
|
||
<a href="#resolve_pers/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><code class="inline">:locale</code> is any valid locale returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <code class="inline">t:Cldr.LanguageTag</code> struct returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new!/2"><code class="inline">Cldr.Locale.new!/2</code></a>
|
||
The default is <code class="inline">options[:backend].get_locale()</code></li></ul><h2 id="resolve_pers/2-examples" class="section-heading">
|
||
<a href="#resolve_pers/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="8594709906-1">(</span><span class="s">"100%"</span><span class="p" data-group-id="8594709906-1">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="o">|></span><span class="w"> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">resolve_pers</span><span class="p" data-group-id="8594709906-2">(</span><span class="p" data-group-id="8594709906-2">)</span><span class="w">
|
||
</span><span class="p" data-group-id="8594709906-3">[</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">:percent</span><span class="p" data-group-id="8594709906-3">]</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="scan/2">
|
||
|
||
<span id="scan/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#scan/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">scan(string, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<p>Scans a string locale-aware manner and returns
|
||
a list of strings and numbers.</p><h2 id="scan/2-arguments" class="section-heading">
|
||
<a href="#scan/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">string</code> is any <code class="inline">String.t</code></p></li><li><p><code class="inline">options</code> is a keyword list of options</p></li></ul><h2 id="scan/2-options" class="section-heading">
|
||
<a href="#scan/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">:number</code> is one of <code class="inline">:integer</code>, <code class="inline">:float</code>,
|
||
<code class="inline">:decimal</code> or <code class="inline">nil</code>. The default is <code class="inline">nil</code>
|
||
meaning that the type auto-detected as either
|
||
an <code class="inline">integer</code> or a <code class="inline">float</code>.</p></li><li><p><code class="inline">:locale</code> is any locale returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <code class="inline">Cldr.LanguageTag.t</code>. The default is <a href="Plausible.Cldr.html#get_locale/0"><code class="inline">Plausible.Cldr.get_locale/0</code></a>.</p></li></ul><h2 id="scan/2-returns" class="section-heading">
|
||
<a href="#scan/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li>A list of strings and numbers</li></ul><h2 id="scan/2-notes" class="section-heading">
|
||
<a href="#scan/2-notes">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Notes
|
||
</a>
|
||
</h2>
|
||
<p>Number parsing is performed by <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Parser.html#parse/2"><code class="inline">Cldr.Number.Parser.parse/2</code></a>
|
||
and any options provided are passed to that function.</p><h2 id="scan/2-examples" class="section-heading">
|
||
<a href="#scan/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7824987831-1">(</span><span class="s">"£1_000_000.34"</span><span class="p" data-group-id="7824987831-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7824987831-2">[</span><span class="s">"£"</span><span class="p">,</span><span class="w"> </span><span class="mf">1000000.34</span><span class="p" data-group-id="7824987831-2">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7824987831-3">(</span><span class="s">"I want £1_000_000 dollars"</span><span class="p" data-group-id="7824987831-3">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7824987831-4">[</span><span class="s">"I want £"</span><span class="p">,</span><span class="w"> </span><span class="mi">1000000</span><span class="p">,</span><span class="w"> </span><span class="s">" dollars"</span><span class="p" data-group-id="7824987831-4">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7824987831-5">(</span><span class="s">"The prize is 23"</span><span class="p" data-group-id="7824987831-5">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7824987831-6">[</span><span class="s">"The prize is "</span><span class="p">,</span><span class="w"> </span><span class="mi">23</span><span class="p" data-group-id="7824987831-6">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7824987831-7">(</span><span class="s">"The lottery number is 23 for the next draw"</span><span class="p" data-group-id="7824987831-7">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7824987831-8">[</span><span class="s">"The lottery number is "</span><span class="p">,</span><span class="w"> </span><span class="mi">23</span><span class="p">,</span><span class="w"> </span><span class="s">" for the next draw"</span><span class="p" data-group-id="7824987831-8">]</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">scan</span><span class="p" data-group-id="7824987831-9">(</span><span class="s">"The loss is -1.000 euros"</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"de"</span><span class="p">,</span><span class="w"> </span><span class="ss">number</span><span class="p">:</span><span class="w"> </span><span class="ss">:integer</span><span class="p" data-group-id="7824987831-9">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7824987831-10">[</span><span class="s">"The loss is "</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1000</span><span class="p">,</span><span class="w"> </span><span class="s">" euros"</span><span class="p" data-group-id="7824987831-10">]</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_approx_string/2">
|
||
|
||
<span id="to_approx_string/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_approx_string/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_approx_string(number, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_approx_string(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">number</a>() | <a href="https://hexdocs.pm/decimal/2.1.1/Decimal.html#t:t/0">Decimal.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) ::
|
||
{:ok, <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Formats a number and applies the <code class="inline">:approximately</code> format for
|
||
a locale and number system.</p><h2 id="to_approx_string/2-arguments" class="section-heading">
|
||
<a href="#to_approx_string/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted.
|
||
See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.html#to_string/3"><code class="inline">Cldr.Number.to_string/3</code></a> for a description of the available
|
||
options.</p></li></ul><h2 id="to_approx_string/2-example" class="section-heading">
|
||
<a href="#to_approx_string/2-example">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Example
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_approx_string</span><span class="w"> </span><span class="mi">1234</span><span class="w">
|
||
</span><span class="p" data-group-id="1461477102-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"~1,234"</span><span class="p" data-group-id="1461477102-1">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_at_least_string/2">
|
||
|
||
<span id="to_at_least_string/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_at_least_string/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_at_least_string(number, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_at_least_string(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">number</a>() | <a href="https://hexdocs.pm/decimal/2.1.1/Decimal.html#t:t/0">Decimal.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) ::
|
||
{:ok, <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Formats a number and applies the <code class="inline">:at_least</code> format for
|
||
a locale and number system.</p><h2 id="to_at_least_string/2-arguments" class="section-heading">
|
||
<a href="#to_at_least_string/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted.
|
||
See <a href="#to_string/2"><code class="inline">Plausible.Cldr.Number.to_string/2</code></a> for a description of the available
|
||
options.</p></li></ul><h2 id="to_at_least_string/2-example" class="section-heading">
|
||
<a href="#to_at_least_string/2-example">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Example
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_at_least_string</span><span class="w"> </span><span class="mi">1234</span><span class="w">
|
||
</span><span class="p" data-group-id="8171912164-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1,234+"</span><span class="p" data-group-id="8171912164-1">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_at_most_string/2">
|
||
|
||
<span id="to_at_most_string/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_at_most_string/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_at_most_string(number, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_at_most_string(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">number</a>() | <a href="https://hexdocs.pm/decimal/2.1.1/Decimal.html#t:t/0">Decimal.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) ::
|
||
{:ok, <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Formats a number and applies the <code class="inline">:at_most</code> format for
|
||
a locale and number system.</p><h2 id="to_at_most_string/2-arguments" class="section-heading">
|
||
<a href="#to_at_most_string/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted.
|
||
See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.html#to_string/3"><code class="inline">Cldr.Number.to_string/3</code></a> for a description of the available
|
||
options.</p></li></ul><h2 id="to_at_most_string/2-example" class="section-heading">
|
||
<a href="#to_at_most_string/2-example">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Example
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_at_most_string</span><span class="w"> </span><span class="mi">1234</span><span class="w">
|
||
</span><span class="p" data-group-id="0344405608-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"≤1,234"</span><span class="p" data-group-id="0344405608-1">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_range_string/2">
|
||
|
||
<span id="to_range_string/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_range_string/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_range_string(range, options \\ [])</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_range_string(<a href="https://hexdocs.pm/elixir/Range.html#t:t/0">Range.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) ::
|
||
{:ok, <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Formats the first and last numbers of a range and applies
|
||
the <code class="inline">:range</code> format for a locale and number system.</p><h2 id="to_range_string/2-arguments" class="section-heading">
|
||
<a href="#to_range_string/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted.
|
||
See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.html#to_string/3"><code class="inline">Cldr.Number.to_string/3</code></a> for a description of the available
|
||
options.</p></li></ul><h2 id="to_range_string/2-example" class="section-heading">
|
||
<a href="#to_range_string/2-example">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Example
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_range_string</span><span class="w"> </span><span class="mi">1234</span><span class="o">..</span><span class="mi">5678</span><span class="w">
|
||
</span><span class="p" data-group-id="5391714519-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1,234–5,678"</span><span class="p" data-group-id="5391714519-1">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_string/2">
|
||
|
||
<span id="to_string/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_string/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_string(number, options \\ default_options())</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_string(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">number</a>() | <a href="https://hexdocs.pm/decimal/2.1.1/Decimal.html#t:t/0">Decimal.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) ::
|
||
{:ok, <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">atom</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Returns a number formatted into a string according to a format pattern and options.</p><h2 id="to_string/2-arguments" class="section-heading">
|
||
<a href="#to_string/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted.</p></li></ul><h2 id="to_string/2-options" class="section-heading">
|
||
<a href="#to_string/2-options">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Options
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">format</code>: the format style or a format string defining how the number is
|
||
formatted. See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Format.html"><code class="inline">Cldr.Number.Format</code></a> for how format strings can be constructed.
|
||
See <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.Format.html#format_styles_for/3"><code class="inline">Cldr.Number.Format.format_styles_for/3</code></a> to return available format styles
|
||
for a locale. The default <code class="inline">format</code> is <code class="inline">:standard</code>.</p></li><li><p>If <code class="inline">:format</code> is set to <code class="inline">:long</code> or <code class="inline">:short</code> then the formatting depends on
|
||
whether <code class="inline">:currency</code> is specified. If not specified then the number is
|
||
formatted as <code class="inline">:decimal_long</code> or <code class="inline">:decimal_short</code>. If <code class="inline">:currency</code> is
|
||
specified the number is formatted as <code class="inline">:currency_long</code> or
|
||
<code class="inline">:currency_short</code> and <code class="inline">:fractional_digits</code> is set to 0 as a default.</p></li><li><p><code class="inline">:format</code> may also be a format defined by CLDR's Rules Based Number
|
||
Formats (RBNF). Further information is found in the module <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Rbnf.html"><code class="inline">Cldr.Rbnf</code></a>.
|
||
The most commonly used formats in this category are to spell out the
|
||
number in a the locales language. The applicable formats are <code class="inline">:spellout</code>,
|
||
<code class="inline">:spellout_year</code>, <code class="inline">:ordinal</code>. A number can also be formatted as roman
|
||
numbers by using the format <code class="inline">:roman</code> or <code class="inline">:roman_lower</code>.</p></li><li><p><code class="inline">currency</code>: is the currency for which the number is formatted. For
|
||
available currencies see <a href="https://hexdocs.pm/ex_cldr_currencies/2.15.0/Cldr.Currency.html#known_currencies/0"><code class="inline">Cldr.Currency.known_currencies/0</code></a>. This option
|
||
is required if <code class="inline">:format</code> is set to <code class="inline">:currency</code>. If <code class="inline">currency</code> is set
|
||
and no <code class="inline">:format</code> is set, <code class="inline">:format</code> will be set to <code class="inline">:currency</code> as well.</p></li><li><p><code class="inline">currency_symbol</code>: Allows overriding a currency symbol. The alternatives
|
||
are:</p><ul><li><code class="inline">:iso</code> the ISO currency code will be used instead of the default
|
||
currency symbol.</li><li><code class="inline">:narrow</code> uses the narrow symbol defined for the locale. The same
|
||
narrow symbol can be defined for more than one currency and therefore this
|
||
should be used with care. If no narrow symbol is defined, the standard
|
||
symbol is used.</li><li><code class="inline">:symbol</code> uses the standard symbol defined in CLDR. A symbol is unique
|
||
for each currency and can be safely used.</li><li>"string" uses <code class="inline">string</code> as the currency symbol</li><li><code class="inline">:standard</code> (the default and recommended) uses the CLDR-defined symbol
|
||
based upon the currency format for the locale.</li></ul></li><li><p><code class="inline">:cash</code>: a boolean which indicates whether a number being formatted as a
|
||
<code class="inline">:currency</code> is to be considered a cash value or not. Currencies can be
|
||
rounded differently depending on whether <code class="inline">:cash</code> is <code class="inline">true</code> or <code class="inline">false</code>.
|
||
*This option is deprecated in favour of <code class="inline">currency_digits: :cash</code>.</p></li><li><p><code class="inline">:currency_digits</code> indicates which of the rounding and digits should be
|
||
used. The options are <code class="inline">:accounting</code> which is the default, <code class="inline">:cash</code> or
|
||
<code class="inline">:iso</code></p></li><li><p><code class="inline">:rounding_mode</code>: determines how a number is rounded to meet the precision
|
||
of the format requested. The available rounding modes are <code class="inline">:down</code>,
|
||
:half_up, :half_even, :ceiling, :floor, :half_down, :up. The default is
|
||
<code class="inline">:half_even</code>.</p></li><li><p><code class="inline">:number_system</code>: determines which of the number systems for a locale
|
||
should be used to define the separators and digits for the formatted
|
||
number. If <code class="inline">number_system</code> is an <code class="inline">atom</code> then <code class="inline">number_system</code> is
|
||
interpreted as a number system. If the <code class="inline">:number_system</code> is
|
||
<code class="inline">binary</code> then it is interpreted as a number system name. See
|
||
<a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.System.html#number_system_names_for/2"><code class="inline">Cldr.Number.System.number_system_names_for/2</code></a>. The default is <code class="inline">:default</code>.</p></li><li><p><code class="inline">:locale</code>: determines the locale in which the number is formatted. See
|
||
<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/0"><code class="inline">Cldr.known_locale_names/0</code></a>. The default is<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#get_locale/0"><code class="inline">Cldr.get_locale/0</code></a> which is the
|
||
locale currently in affect for this <a href="https://hexdocs.pm/elixir/Process.html"><code class="inline">Process</code></a> and which is set by
|
||
<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#put_locale/1"><code class="inline">Cldr.put_locale/1</code></a>.</p></li><li><p>If <code class="inline">:fractional_digits</code> is set to a positive integer value then the number
|
||
will be rounded to that number of digits and displayed accordingly - overriding
|
||
settings that would be applied by default. For example, currencies have
|
||
fractional digits defined reflecting each currencies minor unit. Setting
|
||
<code class="inline">:fractional_digits</code> will override that setting.</p></li><li><p>If <code class="inline">:maximum_integer_digits</code> is set to a positive integer value then the
|
||
number is left truncated before formatting. For example if the number <code class="inline">1234</code>
|
||
is formatted with the option <code class="inline">maximum_integer_digits: 2</code>, the number is
|
||
truncated to <code class="inline">34</code> and formatted.</p></li><li><p>If <code class="inline">:round_nearest</code> is set to a positive integer value then the number
|
||
will be rounded to nearest increment of that value - overriding
|
||
settings that would be applied by default.</p></li><li><p><code class="inline">:minimum_grouping_digits</code> overrides the CLDR definition of minimum grouping
|
||
digits. For example in the locale <code class="inline">es</code> the number <code class="inline">1234</code> is formatted by default
|
||
as <code class="inline">1345</code> because the locale defines the <code class="inline">minimium_grouping_digits</code> as <code class="inline">2</code>. If
|
||
<code class="inline">minimum_grouping_digits: 1</code> is set as an option the number is formatting as
|
||
<code class="inline">1.345</code>. The <code class="inline">:minimum_grouping_digits</code> is added to the grouping defined by
|
||
the number format. If the sum of these two digits is greater than the number
|
||
of digits in the integer (or fractional) part of the number then no grouping
|
||
is performed.</p></li><li><p><code class="inline">:wrapper</code> is a 2-arity function that will be called for each number component
|
||
with parameters <code class="inline">string</code> and <code class="inline">tag</code> where <code class="inline">tag</code> is one of <code class="inline">:number</code>,
|
||
<code class="inline">:currency_symbol</code>, <code class="inline">:currency_space</code>, <code class="inline">:literal</code>, <code class="inline">:quote</code>, <code class="inline">:percent</code>,
|
||
<code class="inline">:permille</code>, <code class="inline">:minus</code> or <code class="inline">:plus</code>. The function must return a string. The
|
||
function can be used to wrap format elements in HTML or other tags.</p></li></ul><h2 id="to_string/2-locale-extensions-affecting-formatting" class="section-heading">
|
||
<a href="#to_string/2-locale-extensions-affecting-formatting">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Locale extensions affecting formatting
|
||
</a>
|
||
</h2>
|
||
<p>A locale identifier can specify options that affect number formatting.
|
||
These options are:</p><ul><li><code class="inline">nu</code>: defines the number system to be used if none is specified by the <code class="inline">:number_system</code>
|
||
option to <a href="#to_string/2"><code class="inline">to_string/2</code></a></li></ul><p>This key is part of the <a href="https://unicode.org/reports/tr35/#u_Extension">u extension</a> and
|
||
that document should be consulted for details on how to construct a locale identifier with these
|
||
extensions.</p><h2 id="to_string/2-wrapping-format-elements" class="section-heading">
|
||
<a href="#to_string/2-wrapping-format-elements">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Wrapping format elements
|
||
</a>
|
||
</h2>
|
||
<p>Wrapping elements is particularly useful when formatting a number with a
|
||
currency symbol and the requirement is to have different HTML formatting
|
||
applied to the symbol than the number. For example:</p><pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="p" data-group-id="9970338140-1">(</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:currency</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="ss">:USD</span><span class="p">,</span><span class="w"> </span><span class="ss">wrapper</span><span class="p">:</span><span class="w"> </span><span class="k" data-group-id="9970338140-2">fn</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:currency_symbol</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="s">"<span class=</span><span class="se">\"</span><span class="s">symbol</span><span class="se">\"</span><span class="s">>"</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="n">string</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="s">"</span>"</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:number</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="s">"<span class=</span><span class="se">\"</span><span class="s">number</span><span class="se">\"</span><span class="s">>"</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="n">string</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="s">"</span>"</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:currency_space</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="s">"<span>"</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="n">string</span><span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="s">"</span>"</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="c">_other</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">string</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="k" data-group-id="9970338140-2">end</span><span class="p" data-group-id="9970338140-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="9970338140-3">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"<span class=</span><span class="se">\"</span><span class="s">symbol</span><span class="se">\"</span><span class="s">>$</span><span class=</span><span class="se">\"</span><span class="s">number</span><span class="se">\"</span><span class="s">>100.00</span>"</span><span class="p" data-group-id="9970338140-3">}</span></code></pre><p>It is also possible and recommended to use the <a href="https://hexdocs.pm/phoenix_html/3.3.1/Phoenix.HTML.Tag.html#content_tag/3"><code class="inline">Phoenix.HTML.Tag.content_tag/3</code></a>
|
||
function if wrapping HTML tags since these will ensure HTML entities are
|
||
correctly encoded. For example:</p><pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="p" data-group-id="5213406201-1">(</span><span class="mi">100</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:currency</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="ss">:USD</span><span class="p">,</span><span class="w"> </span><span class="ss">wrapper</span><span class="p">:</span><span class="w"> </span><span class="k" data-group-id="5213406201-2">fn</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:currency_symbol</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="nc">Phoenix.HTML.Tag</span><span class="o">.</span><span class="n">content_tag</span><span class="p" data-group-id="5213406201-3">(</span><span class="ss">:span</span><span class="p">,</span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">class</span><span class="p">:</span><span class="w"> </span><span class="s">"symbol"</span><span class="p" data-group-id="5213406201-3">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:number</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="nc">Phoenix.HTML.Tag</span><span class="o">.</span><span class="n">content_tag</span><span class="p" data-group-id="5213406201-4">(</span><span class="ss">:span</span><span class="p">,</span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">class</span><span class="p">:</span><span class="w"> </span><span class="s">"number"</span><span class="p" data-group-id="5213406201-4">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="ss">:currency_space</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="nc">Phoenix.HTML.Tag</span><span class="o">.</span><span class="n">content_tag</span><span class="p" data-group-id="5213406201-5">(</span><span class="ss">:span</span><span class="p">,</span><span class="w"> </span><span class="n">string</span><span class="p" data-group-id="5213406201-5">)</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="c">_other</span><span class="w"> </span><span class="o">-></span><span class="w"> </span><span class="n">string</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="k" data-group-id="5213406201-2">end</span><span class="p" data-group-id="5213406201-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="5213406201-6">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"<span class=</span><span class="se">\"</span><span class="s">symbol</span><span class="se">\"</span><span class="s">>$</span><span class=</span><span class="se">\"</span><span class="s">number</span><span class="se">\"</span><span class="s">>100.00</span>"</span><span class="p" data-group-id="5213406201-6">}</span></code></pre><p>When formatting a number the format is parsed into format elements that might include
|
||
a currency symbol, a literal string, inserted text between a currency symbol and the
|
||
currency amount, a percent sign, the number itself and several other elements. In
|
||
some cases it is helpful to be apply specific formatting to each element.
|
||
This can be achieved by specifying a <code class="inline">:wrapper</code> option. This option takes a 2-arity
|
||
function as an argument. For each element of the format the wrapper function is called
|
||
with two parameters: the format element as a string and an atom representing the
|
||
element type. The wrapper function is required to return a string that is then
|
||
inserted in the final formatted number.</p><h2 id="to_string/2-returns" class="section-heading">
|
||
<a href="#to_string/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">{:ok, string}</code> or</p></li><li><p><code class="inline">{:error, {exception, message}}</code></p></li></ul><h2 id="to_string/2-examples" class="section-heading">
|
||
<a href="#to_string/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"12,345"</span><span class="p" data-group-id="6567063444-1">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"12 345"</span><span class="p" data-group-id="6567063444-2">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1345.32</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="ss">:EUR</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"es"</span><span class="p">,</span><span class="w"> </span><span class="ss">minimum_grouping_digits</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-3">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1.345,32 €"</span><span class="p" data-group-id="6567063444-3">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1345.32</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="ss">:EUR</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"es"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-4">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1345,32 €"</span><span class="p" data-group-id="6567063444-4">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"USD"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-5">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"12 345,00 $US"</span><span class="p" data-group-id="6567063444-5">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="s">"#E0"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-6">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1.2345E4"</span><span class="p" data-group-id="6567063444-6">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:accounting</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"THB"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-7">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"THB 12,345.00"</span><span class="p" data-group-id="6567063444-7">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="o">-</span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:accounting</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"THB"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-8">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"(THB 12,345.00)"</span><span class="p" data-group-id="6567063444-8">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:accounting</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"THB"</span><span class="p">,</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"th"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-9">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"฿12,345.00"</span><span class="p" data-group-id="6567063444-9">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:accounting</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"THB"</span><span class="p">,</span><span class="w">
|
||
</span><span class="gp unselectable">...> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"th"</span><span class="p">,</span><span class="w"> </span><span class="ss">number_system</span><span class="p">:</span><span class="w"> </span><span class="ss">:native</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-10">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"฿๑๒,๓๔๕.๐๐"</span><span class="p" data-group-id="6567063444-10">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1244.30</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:long</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-11">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1 thousand"</span><span class="p" data-group-id="6567063444-11">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1244.30</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:long</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"USD"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-12">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1,244 US dollars"</span><span class="p" data-group-id="6567063444-12">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1244.30</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:short</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-13">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"1K"</span><span class="p" data-group-id="6567063444-13">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mf">1244.30</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:short</span><span class="p">,</span><span class="w"> </span><span class="ss">currency</span><span class="p">:</span><span class="w"> </span><span class="s">"EUR"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-14">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"€1K"</span><span class="p" data-group-id="6567063444-14">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">1234</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:spellout</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-15">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"one thousand two hundred thirty-four"</span><span class="p" data-group-id="6567063444-15">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">1234</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:spellout_verbose</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-16">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"one thousand two hundred and thirty-four"</span><span class="p" data-group-id="6567063444-16">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">1989</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:spellout_year</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-17">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"nineteen eighty-nine"</span><span class="p" data-group-id="6567063444-17">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:ordinal</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-18">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"123rd"</span><span class="p" data-group-id="6567063444-18">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="ss">:roman</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-19">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"CXXIII"</span><span class="p" data-group-id="6567063444-19">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"th-u-nu-thai"</span><span class="w">
|
||
</span><span class="p" data-group-id="6567063444-20">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="s">"๑๒๓"</span><span class="p" data-group-id="6567063444-20">}</span></code></pre><h2 id="to_string/2-errors" class="section-heading">
|
||
<a href="#to_string/2-errors">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Errors
|
||
</a>
|
||
</h2>
|
||
<p>An error tuple <code class="inline">{:error, reason}</code> will be returned if an error is detected.
|
||
The two most likely causes of an error return are:</p><ul><li>A format cannot be compiled. In this case the error tuple will look like:</li></ul><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="p" data-group-id="1263533353-1">(</span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">format</span><span class="p">:</span><span class="w"> </span><span class="s">"0#"</span><span class="p" data-group-id="1263533353-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="1263533353-2">{</span><span class="ss">:error</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="1263533353-3">{</span><span class="nc">Cldr.FormatCompileError</span><span class="p">,</span><span class="w">
|
||
</span><span class="s">"Decimal format compiler: syntax error before: </span><span class="se">\"</span><span class="s">#</span><span class="se">\"</span><span class="s">"</span><span class="p" data-group-id="1263533353-3">}</span><span class="p" data-group-id="1263533353-2">}</span></code></pre><ul><li>The format style requested is not defined for the <code class="inline">locale</code> and
|
||
<code class="inline">number_system</code>. This happens typically when the number system is
|
||
<code class="inline">:algorithmic</code> rather than the more common <code class="inline">:numeric</code>. In this case the error
|
||
return looks like:</li></ul><pre><code class="makeup elixir" translate="no"><span class="w"> </span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string</span><span class="p" data-group-id="7267298527-1">(</span><span class="mi">1234</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"he"</span><span class="p">,</span><span class="w"> </span><span class="ss">number_system</span><span class="p">:</span><span class="w"> </span><span class="s">"hebr"</span><span class="p" data-group-id="7267298527-1">)</span><span class="w">
|
||
</span><span class="p" data-group-id="7267298527-2">{</span><span class="ss">:error</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="7267298527-3">{</span><span class="nc">Cldr.UnknownFormatError</span><span class="p">,</span><span class="w">
|
||
</span><span class="s">"The locale :he with number system :hebr does not define a format :standard"</span><span class="p" data-group-id="7267298527-3">}</span><span class="p" data-group-id="7267298527-2">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="to_string!/2">
|
||
|
||
<span id="to_string!/1"></span>
|
||
|
||
<div class="detail-header">
|
||
<a href="#to_string!/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">to_string!(number, options \\ default_options())</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> to_string!(<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">number</a>() | <a href="https://hexdocs.pm/decimal/2.1.1/Decimal.html#t:t/0">Decimal.t</a>(), <a href="https://hexdocs.pm/elixir/Keyword.html#t:t/0">Keyword.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">map</a>()) :: <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>() | <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>()</pre>
|
||
|
||
</div>
|
||
|
||
<p>Same as the execution of <a href="#to_string/2"><code class="inline">to_string/2</code></a> but raises an exception if an error would be
|
||
returned.</p><h2 id="to_string!/2-arguments" class="section-heading">
|
||
<a href="#to_string!/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">number</code> is an integer, float or Decimal to be formatted</p></li><li><p><code class="inline">options</code> is a keyword list defining how the number is to be formatted. See
|
||
<a href="#to_string/2"><code class="inline">Plausible.Cldr.Number.to_string/2</code></a></p></li></ul><h2 id="to_string!/2-returns" class="section-heading">
|
||
<a href="#to_string!/2-returns">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Returns
|
||
</a>
|
||
</h2>
|
||
<ul><li><p>a formatted number as a string or</p></li><li><p>raises an exception</p></li></ul><h2 id="to_string!/2-examples" class="section-heading">
|
||
<a href="#to_string!/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string!</span><span class="w"> </span><span class="mi">12345</span><span class="w">
|
||
</span><span class="s">"12,345"</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">to_string!</span><span class="w"> </span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="ss">locale</span><span class="p">:</span><span class="w"> </span><span class="s">"fr"</span><span class="w">
|
||
</span><span class="s">"12 345"</span></code></pre>
|
||
</section>
|
||
</section>
|
||
<section class="detail" id="validate_number_system/2">
|
||
|
||
<div class="detail-header">
|
||
<a href="#validate_number_system/2" class="detail-link" title="Link to this function">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
<span class="sr-only">Link to this function</span>
|
||
</a>
|
||
<h1 class="signature" translate="no">validate_number_system(locale, number_system)</h1>
|
||
|
||
<a href="https://github.com/plausible/analytics/blob/main/lib/plausible/cldr.ex#L1" class="icon-action" rel="help" title="View Source">
|
||
<i class="ri-code-s-slash-line" aria-hidden="true"></i>
|
||
<span class="sr-only">View Source</span>
|
||
</a>
|
||
|
||
|
||
</div>
|
||
|
||
<section class="docstring">
|
||
|
||
<div class="specs">
|
||
|
||
<pre translate="no"><span class="attribute">@spec</span> validate_number_system(
|
||
<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#t:locale_name/0">Cldr.Locale.locale_name</a>() | <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html#t:t/0">Cldr.LanguageTag.t</a>(),
|
||
<a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.System.html#t:system_name/0">Cldr.Number.System.system_name</a>() | <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.System.html#t:types/0">Cldr.Number.System.types</a>()
|
||
) :: {:ok, <a href="https://hexdocs.pm/ex_cldr_numbers/2.31.3/Cldr.Number.System.html#t:system_name/0">Cldr.Number.System.system_name</a>()} | {:error, {<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">module</a>(), <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()}}</pre>
|
||
|
||
</div>
|
||
|
||
<p>Return a valid number system from a provided locale and number
|
||
system name or type.</p><p>The number system or number system type must be valid for the
|
||
given locale. If a number system type is provided, the
|
||
underlying number system is returned.</p><h2 id="validate_number_system/2-arguments" class="section-heading">
|
||
<a href="#validate_number_system/2-arguments">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Arguments
|
||
</a>
|
||
</h2>
|
||
<ul><li><p><code class="inline">locale</code> is any valid locale name returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_locale_names/1"><code class="inline">Cldr.known_locale_names/1</code></a>
|
||
or a <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.LanguageTag.html"><code class="inline">Cldr.LanguageTag</code></a> struct returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.Locale.html#new!/2"><code class="inline">Cldr.Locale.new!/2</code></a></p></li><li><p><code class="inline">system_name</code> is any number system name returned by
|
||
<a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_number_systems/0"><code class="inline">Cldr.known_number_systems/0</code></a> or a number system type
|
||
returned by <a href="https://hexdocs.pm/ex_cldr/2.37.2/Cldr.html#known_number_system_types/0"><code class="inline">Cldr.known_number_system_types/0</code></a></p></li></ul><h2 id="validate_number_system/2-examples" class="section-heading">
|
||
<a href="#validate_number_system/2-examples">
|
||
<i class="ri-link-m" aria-hidden="true"></i>
|
||
Examples
|
||
</a>
|
||
</h2>
|
||
<pre><code class="makeup elixir" translate="no"><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">validate_number_system</span><span class="w"> </span><span class="s">"en"</span><span class="p">,</span><span class="w"> </span><span class="ss">:latn</span><span class="w">
|
||
</span><span class="p" data-group-id="7792720125-1">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="ss">:latn</span><span class="p" data-group-id="7792720125-1">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">validate_number_system</span><span class="w"> </span><span class="s">"en"</span><span class="p">,</span><span class="w"> </span><span class="ss">:default</span><span class="w">
|
||
</span><span class="p" data-group-id="7792720125-2">{</span><span class="ss">:ok</span><span class="p">,</span><span class="w"> </span><span class="ss">:latn</span><span class="p" data-group-id="7792720125-2">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">validate_number_system</span><span class="w"> </span><span class="s">"en"</span><span class="p">,</span><span class="w"> </span><span class="ss">:unknown</span><span class="w">
|
||
</span><span class="p" data-group-id="7792720125-3">{</span><span class="ss">:error</span><span class="p">,</span><span class="w">
|
||
</span><span class="p" data-group-id="7792720125-4">{</span><span class="nc">Cldr.UnknownNumberSystemError</span><span class="p">,</span><span class="w"> </span><span class="s">"The number system :unknown is unknown"</span><span class="p" data-group-id="7792720125-4">}</span><span class="p" data-group-id="7792720125-3">}</span><span class="w">
|
||
|
||
</span><span class="gp unselectable">iex> </span><span class="nc">Plausible.Cldr.Number</span><span class="o">.</span><span class="n">validate_number_system</span><span class="w"> </span><span class="s">"zz"</span><span class="p">,</span><span class="w"> </span><span class="ss">:default</span><span class="w">
|
||
</span><span class="p" data-group-id="7792720125-5">{</span><span class="ss">:error</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="7792720125-6">{</span><span class="nc">Cldr.InvalidLanguageError</span><span class="p">,</span><span class="w"> </span><span class="s">"The language </span><span class="se">\"</span><span class="s">zz</span><span class="se">\"</span><span class="s"> is invalid"</span><span class="p" data-group-id="7792720125-6">}</span><span class="p" data-group-id="7792720125-5">}</span></code></pre>
|
||
</section>
|
||
</section>
|
||
|
||
</div>
|
||
</section>
|
||
|
||
<footer class="footer">
|
||
<p>
|
||
|
||
<span class="line">
|
||
<button class="a-main footer-button display-quick-switch" title="Search HexDocs packages">
|
||
Search HexDocs
|
||
</button>
|
||
|
||
<a href="Plausible.epub" title="ePub version">
|
||
Download ePub version
|
||
</a>
|
||
|
||
</span>
|
||
</p>
|
||
|
||
<p class="built-using">
|
||
Built using
|
||
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener" translate="no">ExDoc</a> (v0.30.3) for the
|
||
|
||
<a href="https://elixir-lang.org" title="Elixir" target="_blank" translate="no">Elixir programming language</a>
|
||
|
||
</p>
|
||
</footer>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
||
<script>mermaid.initialize({startOnLoad: true})</script>
|
||
|
||
</body>
|
||
</html>
|