Packages
ex_cldr_units
3.3.1
3.20.5
3.20.4
3.20.3
3.20.2
3.20.1
3.20.0
3.19.2
3.19.1
3.19.0
3.18.1
3.18.0
3.17.2
3.17.1
3.17.0
3.16.5
3.16.4
3.16.3
3.16.2
3.16.1
3.16.0
3.15.0
3.14.0
3.13.3
3.13.2
3.13.1
3.13.0
3.12.2
3.12.1
3.12.0
3.11.0
3.10.0
3.9.2
3.9.1
3.9.0
3.8.0
3.8.0-rc.2
3.8.0-rc.1
3.8.0-rc.0
3.7.1
3.7.0
3.6.0
3.5.3
3.5.2
3.5.1
3.5.0
3.5.0-rc.1
3.5.0-rc.0
3.4.0
3.4.0-rc.0
3.3.1
3.3.0
3.3.0-rc.0
3.2.1
3.2.0
3.1.2
3.1.1
3.1.0
3.0.1
3.0.0
3.0.0-rc.0
2.8.1
2.8.0
2.7.0
2.6.1
2.6.0
2.5.3
2.5.2
2.5.1
2.5.0
2.4.0
2.3.3
2.3.2
retired
2.3.1
2.3.0
2.2.0
2.1.0
2.0.0
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
retired
1.0.1
retired
1.0.0
retired
1.0.0-rc.0
retired
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.2.1
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
Unit formatting (volume, area, length, ...), conversion and arithmetic functions based upon the Common Locale Data Repository (CLDR).
Current section
Files
Jump to
Current section
Files
lib/cldr/unit/prefix.ex
defmodule Cldr.Unit.Prefix do
@si_factors %{
"yokto" => Ratio.new(1, 1_000_000_000_000_000_000_000_000),
"zepto" => Ratio.new(1, 1_000_000_000_000_000_000_000),
"atto" => Ratio.new(1, 1_000_000_000_000_000_000),
"femto" => Ratio.new(1, 1_000_000_000_000_000),
"pico" => Ratio.new(1, 1_000_000_000_000),
"nano" => Ratio.new(1, 1_000_000_000),
"micro" => Ratio.new(1, 1_000_000),
"milli" => Ratio.new(1, 1_000),
"centi" => Ratio.new(1, 100),
"deci" => Ratio.new(1, 10),
"deka" => 10,
"hecto" => 100,
"kilo" => 1_000,
"mega" => 1_000_000,
"giga" => 1_000_000_000,
"tera" => 1_000_000_000_000,
"peta" => 1_000_000_000_000_000,
"exa" => 1_000_000_000_000_000_000,
"zetta" => 1_000_000_000_000_000_000_000,
"yotta" => 1_000_000_000_000_000_000_000_000
}
def si_factors do
@si_factors
end
@si_power_prefixes @si_factors
|> Enum.map(fn
{prefix, factor} when is_integer(factor) ->
{prefix, trunc(:math.log10(factor))}
{prefix, %Ratio{denominator: factor}} ->
{prefix, -trunc(:math.log10(factor))}
end)
|> Map.new()
def si_power_prefixes do
@si_power_prefixes
end
@power_units [{"square", 2}, {"cubic", 3}]
def power_units do
@power_units
end
@si_sort_order @si_factors
|> Enum.map(fn
{k, v} when is_integer(v) -> {k, v / 1.0}
{k, v} -> {k, Ratio.to_float(v)}
end)
|> Enum.sort(fn {_k1, v1}, {_k2, v2} -> v1 > v2 end)
|> Enum.map(&elem(&1, 0))
|> Enum.with_index()
def si_sort_order do
@si_sort_order
end
end