# Print variable value in plot title with custom precision after decimal point (Plots.jl)

**URL:** https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861
**Category:** General Usage
**Tags:** plotting
**Created:** [September 14, 2023, 5:25pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861 "2023-09-14T17:25:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)
#### Post date: [September 14, 2023, 5:25pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861/1 "2023-09-14T17:25:44Z")

</div>

Hi all!  
I’m trying to print variable values in the title of a plot using:

```julia
title = L"\eta_1 = %$(mean(df_b.η))"

```

But the result shows many numbers after the decimal point which takes the whole line of the title. How can I control the format of the print?

Thank you!

---

<div class="post-metadata">

### Author: ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)
#### Post date: [September 14, 2023, 5:35pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861/2 "2023-09-14T17:35:19Z")

</div>

You can probably do

```julia
title = L"\eta_1 = %$(round(mean(df_b.η); digits = 2))"

```

And change 2 to your preferred precision

---

<div class="post-metadata">

### Author: ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)
#### Post date: [September 14, 2023, 5:45pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861/3 "2023-09-14T17:45:31Z")

</div>

> [@disberd](#):
>
> `L"\eta_1 = %$(round(mean(df_b.η); digits = 2))"`

This helps only a little, the number that shows is:  
2.2142441546857053e11  
after using your suggestion the display is now:  
2.2142441546857e11

Which helps, but what I need the display to be in the form of:  
2.21e11

---

<div class="post-metadata">

### Author: ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)
#### Post date: [September 14, 2023, 5:49pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861/4 "2023-09-14T17:49:52Z")

</div>

Sorry I only thought about small numbers. For the specific case you could use the `sigdigits` kwarg of round.

There might even be a way with round to do something accurate in both case but I am not at a computer with Julia now.

Another alternative is to use [Printf · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Printf/#Printf.@sprintf)

---

<div class="post-metadata">

### Author: ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)
#### Post date: [September 14, 2023, 6:50pm UTC](https://discourse.julialang.org/t/print-variable-value-in-plot-title-with-custom-precision-after-decimal-point-plots-jl/103861/5 "2023-09-14T18:50:21Z")

</div>

`sigdigits` works! thank you!!!
