Print large Int with _ separators

question

#1

This is part of the read syntax:

julia> 10_000_000
10000000

but how can I print numbers in this format? Just want integers.

PS.: I can work around this with

julia> using Formatting

julia> replace(format(10^7, commas = true), ",", "_")
"10_000_000"

or similar hacks.


#2

You can try something like:

julia> @eval Base begin
           using Formatting
           show(io::IO, i::Signed) = show(io, replace(format(i, commas=true), ",", "_"))
       end;
WARNING: Method definition show(IO, Signed) in module Base at show.jl:259 overwritten at REPL[1]:3.

rand(1:10000, 5, 5)
5×5 Array{Int64,"2"}:
 "6_475"  "7_306"  "1_793"  "2_164"  "2_441"
 "7_282"  "9_051"  "2_813"  "5_542"  "3_969"
 "6_739"  "5_924"  "4_357"  "1_587"    "288"
   "487"  "8_289"  "9_454"  "8_507"    "305"
 "4_025"  "5_789"  "1_285"  "1_833"  "9_989"

It will probably break many things though (including the REPL) :slight_smile:


#3

Perhaps I was not clear (sorry): I am not looking for a solution to change this everywhere, just to print a specific number. I was just surprised that I could not find anything in Base that would support printing in a syntax it reads.


#4

In that case, I think something like Formatting is the correct tool.


#5

Thanks, opened an issue.


#6

Have you seen