Present a sum of money formaly with either a minus or a space, commas every three digits a period and two digits for cents.
| Return Type | Function name | Arguments |
|---|---|---|
| const char* | FormalMoney | (int32_t,) |
Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp
Function Logic:
Function body:
const char* FormalMoney (int32_t nValue)
{
// Category: Text Presentation
//
// Present a sum of money formaly with either a minus or a space, commas every three digits a period and two digits for cents.
//
// Argument: nValue The number to print
//
// Returns: Instance of string by value being the text representation of the supplied value
_hzfunc("FormalMoney") ;
char* i ; // Working buffer pointer
char* pBuf ; // Working buffer
uint32_t M ; // Number of millions (value/100,000,000 cents)
uint32_t T ; // Number of thousands (value%100,000,000/100,000)
uint32_t U ; // Number of units
uint32_t C ; // Number of cents
uint32_t pad ; // For padding calculation
i = pBuf = _thisfn.ScratchPad(16);
i[0]= CHAR_SPACE ;
if (nValue < 0)
{
i[0]= CHAR_MINUS ;
nValue *= -1;
}
M = (nValue / 100000000);
T = (nValue % 100000000)/100000;
U = (nValue % 100000)/100;
C = (nValue % 100);
if (M > 9) pad = 0;
else if (M) pad = 1;
else if (T > 99)pad = 3;
else if (T > 9) pad = 4;
else if (T) pad = 5;
else if (U > 99)pad = 7;
else if (U > 9) pad = 8;
else
pad = 9;
for (i++ ; pad > 0; pad--)
*i++ = CHAR_SPACE ;
if (M) sprintf(i, "%d,%03d,%03d.%02d", M, T, U, C) ;
else if (T) sprintf(i, "%d,%03d.%02d", T, U, C) ;
else if (U) sprintf(i, "%d.%02d", U, C) ;
else sprintf(i, "0.%02d", C) ;
return pBuf ;
}