# Engineering formatting with SI prefixes using Formatting.jl

**URL:** https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107
**Category:** General Usage
**Tags:** formatting
**Created:** [August 23, 2023, 11:10am UTC](https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107 "2023-08-23T11:10:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)
#### Post date: [August 23, 2023, 11:10am UTC](https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107/1 "2023-08-23T11:10:36Z")

</div>

I am trying to use pretty formatting engineering with Formatting.jl but I fail. Is it possible to automatically format numbers with SI prefixes and, ideally, be able to select precision?

E.g.:

0.01 → 10m  
0.022 → 22m  
0.0222 → 22.2m  
0.00001 → 10μ

With Formatting.jl and autoscaling I get:

format(0.00001, autoscale = :metric) → 0.01m

Ideally I would prefer this format: [1–1000){SI prefix}{maybe unit}

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [August 23, 2023, 7:28pm UTC](https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107/2 "2023-08-23T19:28:50Z")

</div>

Not tested enough, but seems to work with your examples:

```julia
using Formatting

function formatSI(x)
  1e-3<abs(x)<1 ? format(1e3*x, autoscale=:metric) * "m" :
  1e-6<abs(x)<1e-3 ? format(1e6*x, autoscale=:metric) * "μ" :
  1e-9<abs(x)<1e-6 ? format(1e9*x, autoscale=:metric) * "n" :
  1e-12<abs(x)<1e-9 ? format(1e12*x, autoscale=:metric) * "p" :
  return format(x, autoscale=:metric)
end

```

---

<div class="post-metadata">

### Author: ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)
#### Post date: [August 24, 2023, 10:26am UTC](https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107/3 "2023-08-24T10:26:50Z")

</div>

Thanks. I was also thinking of doing something similar but I was hoping there would be a magic switch somewhere in Formatting.jl

---

<div class="post-metadata">

### Author: ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)
#### Post date: [June 12, 2025, 7:55am UTC](https://discourse.julialang.org/t/engineering-formatting-with-si-prefixes-using-formatting-jl/103107/4 "2025-06-12T07:55:15Z")

</div>

If anyone cares about the solution I just submitted a [PR](https://github.com/JuliaString/Format.jl/pull/92) to [Format.jl](https://github.com/JuliaString/Format.jl), a successor to [Formatting.jl](https://github.com/JuliaIO/Formatting.jl).
