You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Localize.Unit.localize/2 and a list-of-units overload of Localize.Unit.to_string/2 close the parity gap with Cldr.Unit.localize/3: passing :usage to to_string/2 now resolves the locale-preferred unit set (territory derived from :locale via Localize.Territory.territory_from_locale/1), decomposes the value across it, and joins the parts with the locale's standard list pattern in a single call (e.g. Localize.Unit.to_string(Localize.Unit.new!(1.83, "meter"), usage: :person_height, locale: "en-US") returns {:ok, "6 feet and 0.047 inches"}).
Localize.Unit.Conversion.convert/3 and Localize.Unit.decompose/2 now preserve Decimal precision end-to-end: Decimal inputs flow through Decimal arithmetic instead of round-tripping through float.
Localize.Unit gains a :format_options struct field that localize/2 populates from the skeleton attribute on CLDR's unitPreferenceData (e.g. [round_nearest: 50] for usage: :road distances of 300 m+ in region 001). to_string/2 merges these per-unit options with caller-supplied options and forwards them to the number formatter, so a 311 m road distance now renders as "300 meters" rather than "311 meters". Caller-supplied options win on conflict; usages whose CLDR preferences carry no skeleton (e.g. person-height) are unchanged.
Localize.Unit.Math.round/3 now accepts a rounding mode (:half_up default, plus :half_even, :half_down, :up, :down, :ceiling, :floor); float values are routed through Decimal so every mode produces consistent results. New Localize.Unit.Math.trunc/1 truncates toward zero with the same Decimal/float/integer dispatch as floor/1 and ceil/1.
Localize.Unit.measurement_system_for_territory/2 accepts a category second argument: :default (existing behaviour), :temperature (e.g. :US → :us for Fahrenheit), or :paper_size (:US → :us_letter, :FR → :a4). The category-specific maps in CLDR's measurementData.json only enumerate territories whose category system differs from their default measurement system, so the lookup falls through to the default for any territory not listed in the category map.
Localize.Unit.decompose/3 accepts an optional third format_options argument and stamps it on the trailing (smallest) decomposed unit; intermediate units whose integer part rounds to zero are now skipped, matching cldr_units' behaviour. This is what Localize.Unit.localize/2 uses internally to thread CLDR preference skeletons through to to_string/2.
Localize.Unit.to_string/2 documents :grammatical_gender and :grammatical_case as accepted options, matching the naming used by Cldr.Unit.to_string/3. :grammatical_case selects a case-keyed pattern variant (existing functionality, now documented). :grammatical_gender is accepted for cldr_units API parity but only meaningful for compound-unit patterns; for simple units the gender is fixed by CLDR data and the option has no effect on output.
Localize.Unit.Preference.preferred_units/2 documents :scope and :alt as forward-compatible placeholder options accepted but unused, matching cldr_units API surface. CLDR 48 ships no <unitPreference> carrying these attributes.