okay I have just written a similar function to print a value held on file and output it to a print record thru PRN.
I am sure if you read the function you may be able to adjust it to your rquirements.
the following takes a double value - say 123456.12 - and prints to the print report in the form of 123,456.12.
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;
bal_val *= 100; //
convertval = (long)bal_val;
if(convertval > test1)
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
undermill = convertval / test2;
undermill = undermill % grand;
overmill = convertval / test1;
fprintf(prnt,"%ld,%3ld,%3ld.%2ld \n\n", overmill, undermill, under1000, under100);
}
else if(convertval > test2)
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
undermill = convertval / test2;
fprintf(prnt,"%ld,%3ld.%2ld \n\n", undermill, under1000, under100);
}
else
{
under100 = convertval % tun;
under1000 = convertval % test2;
under1000 = under1000 / tun;
fprintf(prnt,"%ld.%2ld \n\n", under1000, under100);
}
} /* end function monetary_balance */
THIS DOESNOT WORK FOR NEGATIVE NUMBERS Hoping to get certified..in C programming.