stringvar = Str(number)

Command Availability:

Available on all microcontrollers


The Str function will convert a number into a string. number can be any byte or word variable, or a fixed number between 0 and 65535 inclusive.

The string variable stringvar will contain the same number, represented as a string.

This function is especially useful if a number needs to added to the end of a string, or if a custom data sending routine has been created but only supports the output of string variables.


    'Set chip model
    #chip 16F1936

    'Set up hardware serial connection
    #define USART_BAUD_RATE 9600

    'Take an A/D reading
    SensorReading = ReadAD(AN0)

    'Create a string variable
    Dim OutVar As String

    'Fill string with sensor reading
    OutVar = Str(SensorReading)

    HSerPrint OutVar

    When using the functions STR() do not leave space between the function
    call and the left brace. You will get a compiler error that is

    ' use this, note this is no space between the STR and the left brace!
    ' do not use, note the space!
    STR (number_variable)

See Also Hex, Val