How would I insert commas into a large number such as 5.5E9?
Printable View
How would I insert commas into a large number such as 5.5E9?
?????
5.500.000.000 or what?
Your little narative is as cryptic as the C language!!
By the way my compiler is MSVC 6.0, and yes the number is
5,500,000,000 or five point five billion, the population of the
third planet from the sun.
What I need is a comma inserting routine used in conjunction
with the printf function. :-)
Actually, the population is past six billion...
Quzah.
Six billion? I did not know that ... simply wild ... weird wild stuff you find out from this board. Wacky.
I don't know what you mean by "inserting commas". Do you mean making the printout look like this:Quote:
Originally posted by HKR
Your little narative is as cryptic as the C language!!
By the way my compiler is MSVC 6.0, and yes the number is
5,500,000,000 or five point five billion, the population of the
third planet from the sun.
What I need is a comma inserting routine used in conjunction
with the printf function. :-)
5.500.000.000 instead of 5500000000? I doubt there exists such a function, so you have to make your own. However, I don't have MSVC (see my signature) so I might be wrong though...
okay I had same problem with an assignment I have just completed...though I didnot have to go as far as 5billion..I only needed it to go as far as 100,000,000. See if you could extend this, if you can understand the logic.
this function prints a double value parameter, either positive or negative, to the display in format example 1,250.13.
Code:void monetary_balance (double bal_val)
{
const long test1 = 100000000L, test2 = 100000L,
grand = 1000L, tun = 100L;
long under100 = 0L, under1000 = 0L, undermill = 0L,
convertval = 0L, overmill = 0L;
char minus = ' ';
if(bal_val < 0) /* negative value ?*/
{ /* converts to positive */
bal_val -= (bal_val * 2);
minus = '-'; /*minus sign for display or print */
}
bal_val *= 100;
convertval = (long)bal_val;
if(convertval >= test1) /*over 999,999.99*/
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
undermill = convertval / test2;
undermill = undermill % grand;
overmill = convertval / test1;
printf("%c%3ld,%03ld,%03ld.%02ld", minus, overmill, undermill, under1000, under100);
}
else if(convertval >= test2) /*over 999.99*/
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
undermill = convertval / test2;
printf("%c%3ld,%03ld.%02ld ", minus, undermill, under1000, under100);
}
else /*must be under 1000.00*/
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
printf("%c %3ld.%02ld ", minus,under1000,under100);
}
} /* end function monetary_balance */
hey, bigtamscot, thanks for you time; finally a response that
shows some programming expertise!! I can't say the same
for the other responses to my post!!