dec

dec(n, [pad])

Convert an integer to a decimal string, optionally specifying a number of digits to pad to.

Examples

julia> dec(123)
"123"

julia> dec(123, 5)
"00123"

julia> dec(42, 8)
"00000042"
  1. Convert an integer to a decimal string without padding:

    julia> dec(123)
    "123"

    This example converts the integer 123 to a decimal string.

  2. Convert an integer to a decimal string with padding:

    julia> dec(123, 5)
    "00123"

    It pads the decimal string representation of 123 with zeroes to a length of 5 digits.

  3. Convert an integer to a decimal string with greater padding:
    julia> dec(42, 8)
    "00000042"

    This example pads the decimal string representation of 42 with zeroes to a length of 8 digits.

Common mistake example:

julia> dec("42")
ERROR: MethodError: no method matching dec(::String)

In this example, the dec function is mistakenly called with a string argument instead of an integer. Make sure to pass an integer value to dec for correct usage.

See Also

base, big, bytes2hex, cconvert, complex, convert, dec, hex, hex2bytes, hex2num, oct, oftype, parse, promote, signed, unsafe_convert, unsigned, widen,

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: