# How to format a float in annotate

**URL:** <https://discourse.julialang.org/t/how-to-format-a-float-in-annotate/70073>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [October 19, 2021, 10:48pm UTC](https://discourse.julialang.org/t/how-to-format-a-float-in-annotate/70073 "2021-10-19T22:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hdcpereira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdcpereira/32/28705_2.png) [@hdcpereira](https://discourse.julialang.org/u/hdcpereira)\
**Post date:** [October 19, 2021, 10:48pm UTC](https://discourse.julialang.org/t/how-to-format-a-float-in-annotate/70073/1 "2021-10-19T22:48:20Z")

</div>

I’m trying to annotate something in a plot but i’m unable to format the floats i’m working with. I’m trying to change the precision of the float, is it possible with annotate or do I need to do it outside the annotate function? ![Screenshot from 2021-10-19 19-46-57](https://global.discourse-cdn.com/julialang/original/3X/9/c/9c012cbe158c7ccb4f43c7cee928cbdd897ccedf.png)

```julia
plot(temperature, σ, label = "experimental", xlabel = "Temperatura (°C)", ylabel = "Tensão Superficial (dinas/cm)")
plot!(temp_fit, sup_tension(temp_fit, fit.param), label = "mq fit")
annotate!(75, 73, text("a = $a, b = $b", 8))

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [October 19, 2021, 11:13pm UTC](https://discourse.julialang.org/t/how-to-format-a-float-in-annotate/70073/2 "2021-10-19T23:13:15Z")

</div>

You can just do it within the string you’ve passed to `text`:

```julia
annotate!(75, 73, text("a = $(round(a, sigdigits=3)), b = $(round(b, sigdigits=4))", 8))

```

or with the [Printf](https://docs.julialang.org/en/v1/stdlib/Printf/#Printf.@sprintf) standard library,

```julia
annotate!(75, 73, text(@sprintf("a = %0.3f, b = %0.3f", a, b), 8))

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [October 20, 2021, 9:09pm UTC](https://discourse.julialang.org/t/how-to-format-a-float-in-annotate/70073/3 "2021-10-20T21:09:32Z")

</div>

This is what I used to round the floating point numbers

```julia
using Printf

function myrounddigits(x;digits=4)
    num=round(x,digits=digits)
    result = ""
    if digits==0
        result = @sprintf("%-10.0f",num)
    elseif digits==1
        result = @sprintf("%-10.1f",num)
    elseif digits==2
        result = @sprintf("%-10.2f",num)
    elseif digits==3
        result = @sprintf("%-10.3f",num)
    elseif digits==4
        result = @sprintf("%-10.4f",num)
    elseif digits==5
        result = @sprintf("%-10.5f",num)
    elseif digits==6
        result = @sprintf("%-10.6f",num)
    elseif digits==7
        result = @sprintf("%-10.7f",num)
    elseif digits==8
        result = @sprintf("%-10.8f",num)
    end
    return rstrip(result)
end

```

You need the rstrip to strip out all the blank spaces in the result string.
