# Prevent Unitful.jl conversion between monetary units

**URL:** <https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712>\
**Category:** General Usage\
**Tags:** unitful\
**Created:** [October 7, 2023, 8:14pm UTC](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712 "2023-10-07T20:14:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Post date:** [October 7, 2023, 8:14pm UTC](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712/1 "2023-10-07T20:14:09Z")

</div>

I’ve tried defining two different monetary units using

```julia
using Unitful: @dimension, @refunit, @u_str, uconvert

@dimension MU "MU" MonetaryUnit
@refunit USD "USD" USDollar MU false
@refunit EUR "EUR" Euro MU false

```

which unfortunately also results in an automatic conversion

```julia
uconvert(u"EUR", 1000u"USD") # 1000 EUR

```

What would be the proper way to define both `EUR` and `USD`, to e.g. allow conversions from `"EUR/s"` to `"EUR/hr"` or `"USD/s"` to `"USD/hr"`, while making sure that any conversion switching between monetary units fails?

---

<div class="post-metadata">

**Author:** ![cmichelenstrofer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmichelenstrofer/32/44392_2.png) [@cmichelenstrofer](https://discourse.julialang.org/u/cmichelenstrofer)\
**Post date:** [November 22, 2023, 7:43am UTC](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712/2 "2023-11-22T07:43:43Z")

</div>

I think the issue is that both are `refunits`. Instead, you should choose one currency as the reference and define all others in terms of that reference.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [November 22, 2023, 7:53am UTC](https://discourse.julialang.org/t/prevent-unitful-jl-conversion-between-monetary-units/104712/3 "2023-11-22T07:53:56Z")

</div>

You can make each currency unit have its own dimension.
