Currency type with basic algebra and pretty printing

What is the go-to package for converting floating point numbers into currencies that can be added and subtracted and pretty printed on tables?

Found Currencies.jl, CurrencyAmounts.jl and Assets.jl but none of them seem to have what I need. I basically need to convert a vector of floating point into currencies for pretty printing:

julia> BRL.([1, 5, 10])

Try this

using Printf

function fp2currency(n)
      return "\$" * rsplit(@sprintf("%-12.2f",n))[1]

You can use it as

julia> fp2currency(12.34) |> println

julia> fp2currency.([1, 5, 10])
3-element Vector{String}:

You cannot add or subtract. You should only do this when you want to print it out.

If what you want is Currency then you could just use Unitful.jl

Have you checked GitHub - rmsrosa/UnitfulAssets.jl: A supplemental units package for Unitful.jl to handle assets.?

1 Like

Thank you @barucden I will take a look.