# Unitful quantities of something

**URL:** https://discourse.julialang.org/t/unitful-quantities-of-something/101978
**Category:** General Usage
**Tags:** unitful
**Created:** [July 23, 2023, 7:19pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978 "2023-07-23T19:19:44Z")
**Posts on this page:** 5
**Page:** 1

<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: [July 23, 2023, 7:19pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978/1 "2023-07-23T19:19:44Z")

</div>

Say I want to represent concentrations like “milligrams of salt per milligrams of sugar”. Unitful.jl doesn’t seem to support this:

```julia
julia> typeof(3u"mg"/100u"mg")
Float64

```

What would you suggest?

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 23, 2023, 7:30pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978/2 "2023-07-23T19:30:46Z")

</div>

maybe [Defining new units · Unitful.jl](https://painterqubits.github.io/Unitful.jl/stable/newunits/) ?

---

<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: [July 23, 2023, 7:46pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978/3 "2023-07-23T19:46:59Z")

</div>

Following that example I can get

```julia
julia> 3u"myMeter" / 2u"m"
1.5 m m^-1

julia> 3u"myMeter" / 2u"m" |> typeof
Quantity{Float64, NoDims, Unitful.FreeUnits{(m^-1, m), NoDims, nothing}}

julia> 3u"myMeter" / 2u"m" == 3u"m" / 2u"myMeter" 
true

```

which is better than nothing but doesn’t really distinguish between the two quantities.

---

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [July 24, 2023, 5:14pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978/4 "2023-07-24T17:14:22Z")

</div>

Guess, in order to distinguish between such quantities you need to make them different `Dimensions`. In the example, you are just defining a different unit of measurement, i.e., `myMeter`, with a corresponding conversion factor into the standard unit of measurement `m`. It still applies to the same physical quantity/dimension and thus \frac{3 \; \mathrm{myMeter}}{2 m} is a unitless quantity.  
Not sure what the proper physical quantity for `salt per sugar` would/should be? Maybe better to use standard concentration or mass units and separately track to which substances these apply?

---

<div class="post-metadata">

### Author: ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)
#### Post date: [September 19, 2023, 2:02pm UTC](https://discourse.julialang.org/t/unitful-quantities-of-something/101978/5 "2023-09-19T14:02:33Z")

</div>

A bit late to the party but maybe @Raf’s [UnitfulMoles.jl](https://github.com/rafaqz/UnitfulMoles.jl) is helpful?

AFAIK, you can work with custom moles, as below (copy-pasted from the ReadMe):

```julia
julia> using UnitfulMoles, Unitful

julia> @mol A
molA

julia> @mol B
molB

julia> 0.5molA/molB
0.5 molA molB⁻¹

```

but you can’t do the same for other units, like grams. You can maybe create your own package called UnitfulGrams.jl that just replaces UnitfulMoles.jl’s moles for grams? 🤷‍♂️
