# \[ANN\] PrettyNumbers.jl

**URL:** https://discourse.julialang.org/t/ann-prettynumbers-jl/73272
**Category:** Package Announcements
**Created:** [December 17, 2021, 4:56pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272 "2021-12-17T16:56:46Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 17, 2021, 4:56pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/1 "2021-12-17T16:56:46Z")

</div>

Hi!

Long time, no see 🙂 I am passing through a very **big** change, I was pretty much off-line in the previous months.

I just want to announce a very simple package called [PrettyNumbers.jl](https://github.com/ronisbr/PrettyNumbers.jl). The idea is to format numbers in many back-ends (text, HTML, LaTeX, etc.), allowing, for example, to change the decimal base easily. Currently, only the text back-end exists.

```julia
julia> pretty_number(19//86)
¹⁹/₈₆

julia> pretty_number(19//86; compact = false)
19
——
86

julia> pretty_number(1906.1896)
1.90619 · 10³

julia> pretty_number(1906.1896, significand_format = "%.10f")
1.9061896000 · 10³

julia> pretty_number(1906.1896; new_decimal_base = 4)
0.190619 · 10⁴

```

I create this package to help me constructing reports when designing space missions like this one:

 ![Captura de Tela 2021-12-17 às 13.52.02](https://global.discourse-cdn.com/julialang/original/3X/7/6/76d4ff0d34dbc1135ca0aedbd6aa4dfc595de31d.png)

Depending on the size of the satellite, you want to see the results in a different unit (10^-3 Nm, or 10^-5 Nm, and so on). Hence, with PrettyNumbers.jl I can now do this very easily by just using a keyword argument in the function.

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [December 17, 2021, 6:18pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/2 "2021-12-17T18:18:55Z")

</div>

Very nice, thanks for the contribution.

Just a minor formatting comment. Let me cite here the section 7.3.3 Multiplication and division from “ISO 80000-1:2009/Cor 1:2011 Quantities and Units — Part 1: General — Technical Corrigendum 1.” ISO, October 2011. [ISO 80000-1:2009/Cor 1:2011 - Quantities and units — Part 1: General — Technical Corrigendum 1](https://www.iso.org/standard/60241.html) :

> If the point is used as the decimal sign, the cross and not the half-high dot should be used as the multiplication sign between numbers expressed with digits. If the comma is used as the decimal sign, both the cross and the half-high dot may be used as the multiplication sign between numbers expressed with digits.

Perhaps having at least an option of this

```julia
julia> pretty_number(1906.1896)
1.90619 × 10³

```

will be great. If not even having this format as default.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 17, 2021, 6:20pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/3 "2021-12-17T18:20:27Z")

</div>

Thanks for the information! I will definitely implement this feature 🙂 Maybe we can have an option but use the X as the default.

---

<div class="post-metadata">

### Author: ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)
#### Post date: [December 17, 2021, 8:54pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/4 "2021-12-17T20:54:13Z")

</div>

I am a simple man.  
I see a package by @Ronis\_B, it gets added to my startup.jl.

Awesome tool and glad to see you around again!

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 17, 2021, 9:11pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/5 "2021-12-17T21:11:16Z")

</div>

Thanks!! 🙂 I am glad they are being useful for you!

---

<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: [December 18, 2021, 12:38am UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/6 "2021-12-18T00:38:21Z")

</div>

@Ronis_BR, how would you do `pretty_matrix()` ?

A preliminary attempt combining your two awesome packages:

```julia
using PrettyNumbers, PrettyTables
pretty_matrix(M) = pretty_table(pretty_number.(String, M), noheader=true, tf=tf_borderless, alignment=:c)
M = Any[0.001 2e5; 19//86 -1e-3]
pretty_matrix(M)
# result:
  1 ⋅ 10⁻³ 2 ⋅ 10⁵
   ¹⁹/₈₆ -1 ⋅ 10⁻³

```

On a side note, how to keep `π` pretty?

```julia
pretty_number(π) # result: 3.14159

```

Grato 🙂

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 18, 2021, 1:05am UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/7 "2021-12-18T01:05:43Z")

</div>

> [@rafael.guerra](#):
>
> @Ronis_BR, how would you do `pretty_matrix()` ?

Hi @rafael.guerra !

This proposal is more or less what I would do to pretty print a matrix. If you want something more “mathematical” but a little bit more verbose, you can use `tf = tf_matrix`:

```julia
┌ ┐
│ 1 ⋅ 10⁻³ 2 ⋅ 10⁵ │
│ ¹⁹/₈₆ -1 ⋅ 10⁻³ │
└ ┘

```

> [@rafael.guerra](#):
>
> On a side note, how to keep `π` pretty?

Good point! This should be very easy. I just need to add a new renderer for `Irrational{:π}`. I will try 🙂

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 18, 2021, 5:45pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/8 "2021-12-18T17:45:41Z")

</div>

@zdenek_hurak done!

If you use the latest version (0.2.0) the default multiplication sign is `\times` but you can change using the keyword `multiplication_sign`.

@rafael.guerra

Using latest PrettyTables (due to a bug), I think most matrices can be rendered good enough using this:

```julia
julia> using PrettyNumbers, PrettyTables

julia> ft(v, i, j) = pretty_number(String, v);

julia> pretty_matrix(M) = pretty_table(
           M;
           noheader = true,
           formatters = ft,
           alignment_anchor_regex = Dict(0 => [r"\.", r"/"]),
           alignment = :c,
           alignment_anchor_fallback = :r,
           tf = tf_matrix
       );

julia> M = hcat([(randn())^i for i = -5:5], [rand(Any[π, ℯ, randn() * 100]) for i = 0:10], [rand(0:50)//rand(0:50) for i = 0:10]);

julia> pretty_matrix(M)
┌ ┐
│ 1.20536 × 10³ π ⁸/₄₁ │
│ 5.51494 × 10² ℯ ⁴¹/₁₇ │
│ -4.43545 × 10⁻¹ π ⁷/₆ │
│ 4.77558 × 10⁻¹ π ³⁷/₂₁ │
│ 9.69893 5.99425 × 10¹ ⁴⁸/₁₇ │
│ 1 ℯ ⁴⁶/₃₃ │
│ -1.5696 π ⁷/₃ │
│ 1.89858 π ⁷/₃₉ │
│ -5.55123 × 10⁻² ℯ ³⁸/₄₅ │
│ 1.95432 × 10⁻¹ -7.89276 × 10¹ ³/₇ │
│ -1.57892 × 10⁻³ -9.1711 × 10¹ ⁴⁸/₅ │
└ ┘

```

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [December 18, 2021, 7:57pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/9 "2021-12-18T19:57:09Z")

</div>

I assume that `e` in the matrix stands for the Euler’s number. Then I cannot help bothering you once again with a reference to (another) standard: [ISO 80000-2:2019 - Quantities and units — Part 2: Mathematics](https://www.iso.org/standard/64973.html). In section 3 it reads

 ![Screenshot_20211218_205348](https://global.discourse-cdn.com/julialang/original/3X/2/9/29fa9d8ea07c7ad4738baf5bb778607b0896c11f.png)

---

<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: [December 18, 2021, 8:16pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/10 "2021-12-18T20:16:39Z")

</div>

That is the Julia default:

```julia
help?> ℯ
"ℯ" can be typed by \euler<tab>

```

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [December 18, 2021, 8:18pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/11 "2021-12-18T20:18:38Z")

</div>

I see. Then… I don’t know 😀

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [December 18, 2021, 8:48pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/12 "2021-12-18T20:48:48Z")

</div>

Yes! It used to be just `e`, I think, but changed at some point.

---

<div class="post-metadata">

### Author: ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)
#### Post date: [December 18, 2021, 9:05pm UTC](https://discourse.julialang.org/t/ann-prettynumbers-jl/73272/13 "2021-12-18T21:05:12Z")

</div>

Here’s the old discussion of this.

[https://github.com/JuliaLang/julia/pull/10612](https://github.com/JuliaLang/julia/pull/10612)

It looks like Julia adopted the unicode character which is recommended as the natural exponent. And that’s inconsistent with the ISO standard. From [https://unicode.org/charts/PDF/U2100.pdf](https://unicode.org/charts/PDF/U2100.pdf) :

212F ℯ SCRIPT SMALL E  
= error  
= natural exponent  
≈ 0065 e latin small letter e
