# How to display Float64 with more digits

**URL:** https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628
**Category:** General Usage
**Tags:** repl
**Created:** [August 30, 2017, 9:03am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628 "2017-08-30T09:03:35Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [August 30, 2017, 9:03am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/1 "2017-08-30T09:03:35Z")

</div>

I can’t find any reasonable solution to this seemingly simple issue. I want to make arrays of `Float64` print with all their digits in the REPL. What method do I need to redefine for the array below to be printed with as many digits as the scalar?

```julia
julia> randn(2)
2-element Array{Float64,1}:
 1.38958 
 0.337895

julia> randn()
-1.2296217328819647

```

This has proven a surprisingly hard question to google, even though I know I have seen a discussion about this before.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 30, 2017, 10:34am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/2 "2017-08-30T10:34:25Z")

</div>

A quick hack (overwriting the method to ignore the `compact` directive in the `IOContext`):

```julia
<< Base.show(io::IO, x::Union{Float64,Float32}) = Base.Grisu._show(io, x, Base.Grisu.SHORTEST, 0, true, false)
WARNING: Method definition show(IO, Union{Float64, Float32}) in module Grisu at grisu/grisu.jl:120 overwritten in module Main at REPL[0]:1.

<< rand(5)
>> 5-element Array{Float64,1}:
 0.41685881323027596
 0.43774537729371676
 0.8202714955342147 
 0.04893977866057142
 0.10743689580376481

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 30, 2017, 12:16pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/3 "2017-08-30T12:16:10Z")

</div>

Rather than hacks, you can use:

```julia
julia> show(IOContext(STDOUT, :compact=>false), "text/plain", randn(2))
2-element Array{Float64,1}:
  1.3718634685435964 
 -0.13288472215889663

```

That is, you write to an `IOContext` stream with the `:compact` property set to `false`.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 30, 2017, 12:17pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/4 "2017-08-30T12:17:22Z")

</div>

My assumption was that this was supposed to be a “default” setting, e.g. work in the REPL for arrays returned from functions etc.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 30, 2017, 12:25pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/5 "2017-08-30T12:25:54Z")

</div>

See also [https://github.com/JuliaLang/julia/issues/6493](https://github.com/JuliaLang/julia/issues/6493) … as I commented in that thread, it would be really trivial to implement a way to control the options passed by the REPL to its default `IOContext`, if we can just agree on the API.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [August 30, 2017, 12:36pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/6 "2017-08-30T12:36:01Z")

</div>

Something like [https://github.com/JuliaLang/julia/pull/2716](https://github.com/JuliaLang/julia/pull/2716)?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [August 30, 2017, 2:59pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/7 "2017-08-30T14:59:22Z")

</div>

I use

```julia
showfull(io, x) = show(IOContext(io; compact = false, limit = false), x)
showfull(x) = showfull(STDOUT, x)

```

I find it so useful, especially for quick dumping of data, that I put it in [my personal library](https://github.com/tpapp/TKPappKitchenSink.jl/blob/master/src/utilities.jl#L12).

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [August 30, 2017, 4:11pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/8 "2017-08-30T16:11:43Z")

</div>

Thanks for your answers! I was looking for a quick hack, to get many significant digits to copy into a unit test.  
I often did use the `format long` command in matlab, so a simple, supported way of changing this at runtime would be highly appreciated!

---

<div class="post-metadata">

### Author: ![PerezHz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/perezhz/32/1750_2.png) [@PerezHz](https://discourse.julialang.org/u/PerezHz)
#### Post date: [August 31, 2017, 7:20pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/9 "2017-08-31T19:20:53Z")

</div>

> [@kristoffer.carlsson](#):
>
> Base.show(io::IO, x::Union{Float64,Float32}) = Base.Grisu.\_show(io, x, Base.Grisu.SHORTEST, 0, true, false)

Just for the record, I found that for `Array{Array{Float64}}` and other kinds of nestings the best solution is the one provided by @kristoffer.carlsson:

```julia
julia> aa = map(x->rand(2), 1:30);

julia> show(aa)
Array{Float64,1}[[0.0213247, 0.948015], [0.138881, 0.40988], [0.607954, 0.247514], [0.961001, 0.800016], [0.795015, 0.196375], [0.419876, 0.210042], [0.147419, 0.596204], [0.655934, 0.33775], [0.261628, 0.0353036], [0.519283, 0.739367], [0.230638, 0.424647], [0.688784, 0.783928], [0.044198, 0.903389], [0.586573, 0.00641704], [0.277042, 0.507606], [0.101339, 0.800158], [0.666822, 0.733885], [0.87061, 0.571897], [0.332233, 0.938371], [0.869072, 0.480484], [0.51722, 0.170909], [0.580332, 0.808131], [0.759806, 0.740258], [0.698577, 0.111267], [0.240175, 0.627679], [0.550143, 0.461072], [0.973468, 0.718771], [0.0565576, 0.264779], [0.817806, 0.608844], [0.628226, 0.437315]]
julia> Base.show(io::IO, x::Union{Float64,Float32}) = Base.Grisu._show(io, x, Base.Grisu.SHORTEST, 0, true, false)
WARNING: Method definition show(IO, Union{Float64, Float32}) in module Grisu at grisu/grisu.jl:120 overwritten in module Main at REPL[3]:1.

julia> show(aa)
Array{Float64,1}[[0.021324667397920383, 0.9480149215510971], [0.138880834453613, 0.40987972158543085], [0.6079541294971065, 0.24751390731387568], [0.9610008104594108, 0.8000157649253907], [0.7950146270582541, 0.19637533429629594], [0.4198755613318861, 0.21004159997572347], [0.14741911239782546, 0.5962040289294155], [0.6559335926380139, 0.33775026650517614], [0.26162809258798947, 0.03530358291261915], [0.5192830984181518, 0.7393666634519216], [0.23063800042570692, 0.4246473510698796], [0.6887842499592063, 0.7839281077852538], [0.04419801672455703, 0.9033893804858726], [0.5865728668047527, 0.006417043034595338], [0.2770423434991949, 0.5076055668589032], [0.1013389015445827, 0.800157991794983], [0.6668216663063329, 0.7338845843658275], [0.8706098748990936, 0.571896899630201], [0.33223293436102663, 0.9383705916674328], [0.8690723007002836, 0.480483678396469], [0.5172200765245383, 0.1709090967694149], [0.5803315111363412, 0.808131364624961], [0.7598063175372176, 0.7402582072192914], [0.6985771670962562, 0.11126665093090793], [0.24017453001037214, 0.6276793732495389], [0.5501427472686542, 0.4610718061669279], [0.9734682038049125, 0.7187708095005967], [0.05655757945487383, 0.2647792748418938], [0.817805627665227, 0.6088441410524292], [0.6282263186278678, 0.43731495814963006]]

```

This is really helpful!

---

<div class="post-metadata">

### Author: ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)
#### Post date: [May 27, 2021, 12:19am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/10 "2021-05-27T00:19:21Z")

</div>

This thread comes top when searching for “Julia display more digits in REPL”, but some of the suggestions are outdated. Likewise for the [second-highest thread.](https://discourse.julialang.org/t/compact-float-printing-in-the-repl/4561)

As of Julia 1.6, `Base.Grisu` was moved to the [Grisu.jl](https://github.com/JuliaAttic/Grisu.jl) package. This is mostly for backward-compatibility. I’d be grateful if you would share the **Post-1.6** recommended approach to have more digits displayed in the REPL. And, as an extra, would be grateful if you would state whether the same method work for displaying digits inline. Thanks! 😃

---

<div class="post-metadata">

### Author: ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)
#### Post date: [May 27, 2021, 12:36am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/11 "2021-05-27T00:36:02Z")

</div>

This is what I’ve been using, but I don’t know any better:

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

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 27, 2021, 9:02am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/12 "2021-05-27T09:02:07Z")

</div>

> [@ptoche](#):
>
> some of the suggestions are outdated

That may not be surprising as the topic is 4 years old at this point.

I think that Discourse warns you about replying to old topics, please kindly consider that and only revive these if you have a compelling reason.

If you have a question, feel free to start a new topic.

---

<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: [May 27, 2021, 9:47am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/13 "2021-05-27T09:47:38Z")

</div>

A similar solution was posted by @Seif_Shebl[here](https://discourse.julialang.org/t/how-to-print-a-number-to-x-digits/50526/2).

To further increase the number of printed digits, say to 100, one can use BigFloats:

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

julia> BigFloat(pi)
3.1415926535897932384626433832795028841971693993751058209749445923078164062861980294536250318213496467

```

---

<div class="post-metadata">

### Author: ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)
#### Post date: [May 27, 2021, 11:44am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/14 "2021-05-27T11:44:53Z")

</div>

> [@Tamas\_Papp](#):
>
> I think that Discourse warns you about replying to old topics, please kindly consider that and only revive these if you have a compelling reason.

I know. It’s a tricky one. As I wrote, This thread comes top when searching for “Julia display more digits in REPL”. I’ll start a new discussion.

---

<div class="post-metadata">

### Author: ![carloslesmes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carloslesmes/32/18882_2.png) [@carloslesmes](https://discourse.julialang.org/u/carloslesmes)
#### Post date: [June 13, 2021, 12:04pm UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/15 "2021-06-13T12:04:54Z")

</div>

Use the function big:

```julia
big.(rand(2))

```

---

<div class="post-metadata">

### Author: ![ink](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ink/32/212560_2.png) [@ink](https://discourse.julialang.org/u/ink)
#### Post date: [October 11, 2024, 9:33am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/16 "2024-10-11T09:33:50Z")

</div>

I had to change some things for this to work, btw. Thanks for the snippet!

```julia
showfull(io, x) = show(IOContext(io, :compact => false, :limit => false), x)
showfull(x) = showfull(stdout, x)

```

Julia’s println() truncating digits caused precision errors for me when using the data in other programs later on. I needed full precision.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [October 11, 2024, 11:36am UTC](https://discourse.julialang.org/t/how-to-display-float64-with-more-digits/5628/17 "2024-10-11T11:36:20Z")

</div>

> [@ink](#):
>
> Julia’s println() truncating digits caused precision errors for me when using the data in other programs later on. I needed full precision.

If you are saving floating-point data for use in other programs, I would think about using a standard file format, which should take care of the precision issue. e.g. HDF5.jl for a binary format (the most compact way to save at full precision), or CSV via DelimitedFiles.jl or CSV.jl, or JSON via JSON.jl, or …
