print_shortest

print_shortest(io, x)

Print the shortest possible representation, with the minimum number of consecutive non-zero digits, of number x, ensuring that it would parse to the exact same number.

Examples

julia> io = IOBuffer();
julia> print_shortest(io, 123.456)
5-element Array{UInt8,1}:
 0x31
 0x32
 0x33
 0x2e
 0x34

Common examples of its use:

  1. Print the shortest representation of a floating-point number:

    julia> io = IOBuffer();
    julia> print_shortest(io, 3.14159)
    6-element Array{UInt8,1}:
    0x33
    0x2e
    0x31
    0x34
    0x31
    0x35

    This example prints the shortest representation of the number 3.14159 as a sequence of UTF-8 bytes.

  2. Print the shortest representation of an integer:

    julia> io = IOBuffer();
    julia> print_shortest(io, 1000)
    4-element Array{UInt8,1}:
    0x31
    0x30
    0x30
    0x30

    It prints the shortest representation of the integer 1000.

  3. Print the shortest representation of a negative number:
    julia> io = IOBuffer();
    julia> print_shortest(io, -42.42)
    6-element Array{UInt8,1}:
    0x2d
    0x34
    0x32
    0x2e
    0x34
    0x32

    It prints the shortest representation of the negative number -42.42.

Common mistake example:

julia> io = IOBuffer();
julia> print_shortest(io, "Hello")
ERROR: MethodError: no method matching print_shortest(::IOBuffer, ::String)

In this example, the function print_shortest is called with a String argument, which is not supported. It's important to ensure that the argument x is a number that can be represented as a valid Julia number.

See Also

:@printf, :@sprintf, display, displayable, dump, info, isprint, print, println, print_escaped, print_joined, print_shortest, print_unescaped, print_with_color, pushdisplay, redisplay, show, showall, showcompact, sprint, versioninfo,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: