Skip to content

Commit

Permalink
avoid hardcoding decimal precision digits
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloose committed Feb 2, 2024
1 parent 324ac8c commit a48eeea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion urn.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <jansson.h>
#include "urn.h"

#define DECIMAL_PRECISION_ON_SCREEN 2

long long urn_time_now(void) {
struct timespec timespec;
clock_gettime(CLOCK_MONOTONIC, &timespec);
Expand Down Expand Up @@ -67,7 +69,7 @@ static void urn_time_string_format(char *string,
sprintf(dot_subsecs, ".%06lld", time % 1000000LL);
if (!serialized) {
/* Show only a dot and 2 decimal places instead of all 6 */
dot_subsecs[3] = '\0';
dot_subsecs[DECIMAL_PRECISION_ON_SCREEN + 1] = '\0';
}
if (millis) {
strcpy(millis, &dot_subsecs[1]);
Expand Down

0 comments on commit a48eeea

Please sign in to comment.