# How to print a number to X digits?

**URL:** <https://discourse.julialang.org/t/how-to-print-a-number-to-x-digits/50526>\
**Category:** New to Julia\
**Tags:** repl, io\
**Created:** [November 21, 2020, 7:27am UTC](https://discourse.julialang.org/t/how-to-print-a-number-to-x-digits/50526 "2020-11-21T07:27:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [November 21, 2020, 8:27am UTC](https://discourse.julialang.org/t/how-to-print-a-number-to-x-digits/50526/2 "2020-11-21T08:27:16Z")

</div>

```julia
julia> using Printf

julia> a = 1;

julia> @printf("%.3f\n", a)
1.000

```

There’s also `@sprintf` to get a string value, see [Printf · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Printf/) for details.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-print-a-number-to-x-digits/50526)._
