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 TypeFunction nameArguments
const char*FormalMoney(int32_t,)

Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp

Function Logic:

0:START 1:pBuf i i 2:unknown 3:i - nValue nValue 4:M nValue ( T nValue ( U nValue C 5:unknown 6:pad 7:M 8:pad 9:T>99 10:pad 11:T>9 12:pad 13:T 14:pad 15:U>99 16:pad 17:U>9 18:pad 19:pad 20:unknown 21:* 22:unknown 23:items 24:T 25:items 26:U 27:items 28:items 29:Return pBuf

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 ;
}