All pastes #271964 Raw Edit

Mine

public c v1 · immutable
#271964 ·published 2006-12-08 16:30 UTC
rendered paste body
/* 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;        rtapi_snprintf(buf, sz, "%s%d.%0*d", sign, whole, nplaces, (int)frac);}