|
mnyfmt.c: Format money or currency amounts
|
Implementation for mnyfmt().
More...
#include "mnyfmt.h"Go to the source code of this file.
Functions | |
| char * | mnyfmt (char *fmtstr, char dec, mnyfmt_long moneyval, unsigned CE) |
Formats and stores in fmtstr the money amount. More... | |
| char* mnyfmt | ( | char * | fmtstr, |
| char | dec, | ||
| mnyfmt_long | moneyval, | ||
| unsigned | CE | ||
| ) |
Formats and stores in fmtstr the money amount.
Before invocation, the formatting pattern (picture clause) is stored in result string fmtstr. To avoid using (double) values that have many round off problems, the parameter for this function is an integer scaled to 10^CE digits. For example, when using CE==2 digits, the monetary value "$2,455.87" is representad by the integer '245587', and if CE==4 digits are used, the integer value would be '24558700'.
moneyval.fmtstr with the formatted value.fmtstr untouched and returns (char*)(0).fmtstr does not have enough format characters '9' for the integer part to format, of if the '-' cannot fit on top of a '9' character, fmtstr remains untouched and the value returned is (char*)(0).fmtstr untouched and the value returned is (char*)(0) ].dec is the decimal fraction separator (usually '.' or ',').dec does not appear in fmtstr it is assumed to be '\0' (end of string character).dec separator all the leading consecutive '9' format characters are substituted with the corresponding digit from the decimal part in moneyval, using digit zero '0' as fill character.moneyval."9999.9999" wild yield "0123.8700" as result when moneyval==1238700 and CE==4.dec separator that are not the '9' format digit are left untouched.'9' appearing before the decimal separator dec will be replaced by digit zero '0' if the corresponding digit in moneyval is not significant.moneyval is negative, the '-' sign will be place over the '9' immediately before the more significant digit.fmtstr are left untouched.'-' and it is always placed on top of the corresponding format character.(char*)(0) when the formatted value does not fit within strlen(fmtstr) characters.fmtstr or to the '-' sign if the formatted value is negative.fmtstr, the programmer must ensure that fmtstr is big enough to hold the format string.'9' character in fmtstr for its corresponding decimal digit, or '0' when it is not a significant digit. All other characters within fmtstr remain untouched.fmtstr is big enough to copy on it the complete format string, as otherwise memory beyond fmtstr would be overwritten.(wchart_t) version for this function, as it is meant to place digits in a formatting string. After placement, the result string can be converted to other forms.
1.8.9.1