format-two-digits

ulihorn/time/format-two-digits

No description
format-two-digits
@/format-two-digits
INnumber
format-two-digits
IN
OUT
OUTstring
To use the node in your project you should have the ulihorn/time library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    char buff[3];
    CStringView view;

    State() : view(buff) {}
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto state = getState(ctx);
    auto n = getValue<input_IN>(ctx);

    // convert to an integer in range 0-99
    uint8_t ndec =
        (n < 0) ? 0 :
        (n > 99) ? 99 :
        (uint8_t)n;

    // convert to characters, leave the last
    // char intact as it always \x00
    state->buff[0] = '0' + ndec / 10;
    state->buff[1] = '0' + ndec % 10;

    emitValue<output_OUT>(ctx, XString(&state->view));
}