본문 바로가기

# RTEMS

[RTEMS] double 소수점 출력 함수 구현

728x90
반응형
/* Helper function to print double as integer with 2 decimal places */
static void print_double_as_int(const char* prefix, double value, const char* suffix) {
    int integer_part = (int)value;
    int decimal_part = (int)((value - integer_part) * 100);
    if (decimal_part < 0) decimal_part = -decimal_part; /* Handle negative decimals */
    printf("%s%d.%02d%s", prefix, integer_part, decimal_part, suffix);
}

// 사용
    print_double_as_int("", (double)rtems_clock_get_uptime_nanoseconds() / 1000000.0, " ms)\n");
728x90
반응형