Formatting Jula REPL Numbers

In MatLab / Octave, you can send the command " format long g " and have the default numeric output in REPL, formatted as follows:

octave> 95000 / 0.05

ans = 1900000

Is it possible to get similar behavior in Julia? Currently with julia

Version 0.3.0-preerelease + 3930 (2014-06-28 17:54 UTC)

Commit bdbab62 * (6-day wizard)

x86_64-RedHat-Linux

I get the following number format.

julia> 95000 / 0.05

1.9e6

+4
source share
1 answer

@printf . C printf, printf C , .

julia> @printf("Integer Format: %d",95000/0.05);
Integer Format: 1900000

julia> @printf("As a String: %s",95000/0.05);
As a String: 1.9e6

julia> @printf("As a float with column sized larger than needed:%11.2f",95000/0.05);
As a float with column sized larger than needed: 1900000.00

REPL @printf , REPL Julia Base.REPL , , :

function display(d::REPLDisplay, ::MIME"text/plain", x)
    io = outstream(d.repl)
    write(io, answer_color(d.repl))
    writemime(io, MIME("text/plain"), x)
    println(io)
end

Float64, writemime Float64.

julia> 95000/0.05
1.9e6

julia> Base.Multimedia.writemime(stream,::MIME"text/plain",x::Float64)=@printf("%1.2f",x)
writemime (generic function with 13 methods)

julia> 95000/0.05
1900000.00
+4

Source: https://habr.com/ru/post/1547217/


All Articles