# Compact display of Floats with @show?

**URL:** <https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554>\
**Category:** General Usage\
**Tags:** pretty-printing\
**Created:** [April 16, 2023, 5:53pm UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554 "2023-04-16T17:53:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [April 16, 2023, 5:53pm UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554/1 "2023-04-16T17:53:24Z")

</div>

```julia
julia> Base.active_repl.options.iocontext[:compact]=true
true

julia> e = exp(1)
2.71828

julia> @show e;
e = 2.718281828459045

```

---

<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:** [April 16, 2023, 6:12pm UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554/2 "2023-04-16T18:12:05Z")

</div>

Try:

```julia
using Printf
Base.show(io::IO, f::Float64) = @printf(io, "%.5f", f)

```

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [April 16, 2023, 6:48pm UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554/3 "2023-04-16T18:48:49Z")

</div>

well, better

```julia
using Printf
Base.show(io::IO, f::Float64) = @printf(io, "%5g", f)

```

otherwise small numbers are shown as zeros

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 19, 2023, 3:21pm UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554/4 "2023-05-19T15:21:51Z")

</div>

The next question. After I had set the compact display as above, I needed an exact value of a variable. How can I get it?

```julia
julia> x = 0.012345678901234
0.012345678901234

julia> using Printf

julia> Base.show(io::IO, f::Float64) = @printf(io, "%5g", f)

julia> x
0.0123457

julia> Base.show(io::IO, f::Float64) = @printf(io, "%15g", f)

julia> x
      0.0123457 # the only difference now it's displayed with an offset

```

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 21, 2023, 11:17am UTC](https://discourse.julialang.org/t/compact-display-of-floats-with-show/97554/5 "2023-05-21T11:17:25Z")

</div>

A workaround solution to my question above:

```julia
julia> x = 0.012345678901234
0.0123457

julia> string(x)
"0.012345678901234"

```
