rendered paste body#ifdef RTAPI#include "rtapi.h"#define snprintf rtapi_snprintf#else#include "stdio.h"#endif /* This function can format decimal numbers whose magnitude is less than 2**31, and when nplaces is less than 9 */void format_decimal(char *buf, int sz, int nplaces, double value) { char *sign = ""; double frac; int whole, i; if(value < 0) { sign = "-"; value = -value; } whole = value; frac = value - whole; for(i=0; i<nplaces; i++) frac *= 10; frac += .5; snprintf(buf, sz, "%s%d.%0*d", sign, whole, nplaces, (int)frac);} #ifdef TEST#include "stdlib.h"int main(int argc, char **argv) { int i; for(i=1; i<argc; i++) { double v = atof(argv[i]); char buf[32]; format_decimal(buf, 31, 4, v); printf("%s\n", buf); } } #endif