|
From: | Dave Hansen |
Subject: | RE: [avr-gcc-list] sprintf - formated output as XXX.XXX.XXX |
Date: | Thu, 06 Jan 2005 12:39:30 -0500 |
From: honschu <address@hidden> [...]
sprintf( lcd_str1, "HSync %lu", value ); lcd_puts( lcd_str1 ); the LCD prints out something like: "HSync 80000000" but because of the big values, I would love to get a more readable format output as "HSync 80.000.000". Can anyone please help me?
I don't believe there is a standard way to do this. The following is untested and not an extremely clever method, but should come close to working:
char const start_fmt[] = "%3lu"; char const cont_fmt[] = ",%03lu"; char cont = 0; unsigned long temp; unsigned long div; for (div = 1000000000; div > 0; div/=1000) { temp = value/div; if (cont) { printf(cont_fmt, temp); } else if (temp) { printf(start_fmt, temp); cont = 1; } value -= temp*div; } HTH, -=Dave
[Prev in Thread] | Current Thread | [Next in Thread] |