Closed LostKobrakai closed 5 years ago
Yes, it should support Decimal since all the Cldr libs should be consistent in this respect. Will add it to the weekend list to fix.
Fixed, sorry it took so long. Published on hex as version 1.2.2
Can we make cldr_unit use only decimals internally? ex_cldr does depend on decimal anyways and results like the ones below just aren't nice to work with. (this is on 1.3.0)
iex(12)> Cldr.Unit.new!(Decimal.new(28800), :second) |> Cldr.Unit.convert(:minute)
#Unit<:minute, #Decimal<480.009600>>
Actually its all decimal calculations for a Unit
that is decimal-based.
But even using decimals, the current conversion strategy, which always has two steps: to a common unit, then to the desired unit, has issues. For example:
iex> to_microsecond = Decimal.new("1.0e-6")
#Decimal<0.0000010>
iex> to_minute = Decimal.new("1.6667e-8")
#Decimal<1.6667E-8>
iex> Decimal.div(m, to_microsecond) |> Decimal.mult(to_minute)
#Decimal<480.00960>
So two thoughts:
seconds
to minutes
is 60
.@kipcole9 Maybe we can just flip the numbers from representing fractions of the smallest unit to be how many of the smallest unit fits into the current one: https://gist.github.com/LostKobrakai/4419bd3c245272e2fc04ef857c3e0f4a
As cldr is already requiring the decimal library, couldn't
Cldr.Unit
normalize to just using Decimal internally?