ÿþ/ /   f i n C a l c M a i n . j s   -   C o p y r i g h t   S u m m e r s o f t   2 0 1 1  
 / /                  
 / /   j s   r e q u i r e m e n t s :  
 / /  
  
 / / a l e r t ( " + f i n C a l c M a i n . j s   -   l o a d i n g " ) ;  
  
 v a r   s p r e a d S h e e t D e b u g   =   f a l s e ;  
  
 / / a l e r t ( 1 ) ;  
  
 f u n c t i o n   r e f r e s h R C ( c e l l N a m e ,   v a l u e )   {  
         v a r   o l d V a l u e ;  
         v a r   n e w V a l u e ;  
         v a r   n e w I m g N a m e ;  
          
         i f   ( c e l l N a m e   = =   " F 6 "   | |   c e l l N a m e   = =   " F 1 6 " )   {  
                 / /   i n p u t   f i e l d s  
         }   e l s e   {  
                 t r y   {  
                         o l d V a l u e   =   $ ( c e l l N a m e ) . f i r s t C h i l d . i n n e r H T M L ;  
                         n e w V a l u e   =   a d d C o m m a s ( r o u n d _ d e c i m a l s ( v a l u e ,   2 ) . t o F i x e d ( 2 ) ) ;  
                         i f   ( n e w V a l u e   ! =   o l d V a l u e )   {  
                                 i f   ( $ ( c e l l N a m e ) . p a r e n t N o d e . a l t I m g N u m b e r   = =   u n d e f i n e d )   {  
                                         $ ( c e l l N a m e ) . p a r e n t N o d e . a l t I m g N u m b e r   =   0 ;  
                                 }  
                                 $ ( c e l l N a m e ) . p a r e n t N o d e . a l t I m g N u m b e r   =   1   -   p a r s e I n t ( $ ( c e l l N a m e ) . p a r e n t N o d e . a l t I m g N u m b e r ) ;  
                                 n e w I m g N a m e   =   " u r l ( i m a g e s / g l o w B "   +   $ ( c e l l N a m e ) . p a r e n t N o d e . a l t I m g N u m b e r   +   " . g i f ) " ;  
                                 $ ( c e l l N a m e ) . i n n e r H T M L   =  
                                         " < s p a n   s t y l e = ' b a c k g r o u n d :   "   +   n e w I m g N a m e   +   " ' > "   +  
                                         n e w V a l u e   +  
                                         " < / s p a n > " ;  
                         }  
                 }   c a t c h   ( e x )   {  
                         / /   h i d d e n   c e l l s   m i g h t   n o t   e x i s t   i n   h t m l . . . .  
                 }  
         }  
 }  
  
 / / a l e r t ( 2 ) ;  
  
 / /   v b   I I F   f u n c t i o n  
 f u n c t i o n   i i f ( c o n d ,   a ,   b )   {  
         r e t u r n   c o n d   ?   a   :   b ;  
 }  
  
 / / a l e r t ( 3 ) ;  
  
 f u n c t i o n   $ ( i d )   {  
         r e t u r n   d o c u m e n t . g e t E l e m e n t B y I d ( i d ) ;  
 }  
  
 f u n c t i o n   r o u n d _ d e c i m a l s ( o r i g i n a l _ n u m b e r ,   d e c i m a l s )   {  
  
         v a r   r e s u l t 1   =   o r i g i n a l _ n u m b e r   *   M a t h . p o w ( 1 0 ,   d e c i m a l s )  
         v a r   r e s u l t 2   =   M a t h . r o u n d ( r e s u l t 1 )  
         v a r   r e s u l t 3   =   r e s u l t 2   /   M a t h . p o w ( 1 0 ,   d e c i m a l s )  
  
         / / r e t u r n   r e s u l t 3 . t o F i x e d ( d e c i m a l s ) ;   / /   f a i l s !   N a N  
         r e t u r n   r e s u l t 3 ;  
  
 }  
  
 / /                  
 / /   e x c e l   r e q u i r e m e n t s :  
 / /  
  
 f u n c t i o n   c a l c u l a t e _ p a y m e n t ( P V ,   I R ,   N P )   {  
         v a r   P M T   =   ( P V   *   I R )   /   ( 1   -   M a t h . p o w ( 1   +   I R ,   - N P ) ) ;  
         r e t u r n   r o u n d _ d e c i m a l s ( P M T ,   2 ) ;  
 }  
  
 / /   e x c e l   f u n c t i o n  
 f u n c t i o n   P M T ( i r ,   n p ,   p v ,   f v )   {  
  
         p v   =   - p v  
  
         r e t u r n   c a l c u l a t e _ p a y m e n t ( p v ,   i r ,   n p ) ;  
  
         / *  
         p v   -   p r e s e n t   v a l u e  
         i r   -   i n t e r e s t   r a t e   p e r   m o n t h  
         n p   -   n u m b e r   o f   p e r i o d s   ( m o n t h s )  
         f v   -   f u t u r e   v a l u e   ( r e s i d u a l   v a l u e   /   b a l l o o n   p a y m e n t )  
         * /  
         p m t   =   ( i r   *   ( p v   *   M a t h . p o w ( ( i r   +   1 ) ,   n p )   +   f v ) )   /   ( ( i r   +   1 )   *   ( M a t h . p o w ( ( i r   +   1 ) ,   n p )   -   1 ) ) ;  
         r e t u r n   p m t ;  
 }  
  
 / /   e x c e l   f u n c t i o n  
 f u n c t i o n   R O U N D ( n u m ,   d e c )   {  
         r e t u r n   r o u n d _ d e c i m a l s ( p a r s e F l o a t ( n u m   +   "   " ) ,   d e c ) ;  
 }  
  
 / /   d e b u g :   t e s t   =   7 3 6 . 5 4  
 / / r e f r e s h R C ( " " ,   P M T ( ( 0 . 2 2 1   /   1 2 ) ,   2 4 ,   - 1 4 1 8 4 ,   0 ) ) ;  
  
 / / a l e r t ( 4 ) ;  
  
 / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
  
 / /                  
 / /   e v a l u a t i o n   r e q u i r e m e n t s :  
 / /  
  
 / /   c u r r e n t   e v a l u a t i o n   c y c l e  
 v a r   c y c l e   =   0 ;  
  
 / /   t h i s   i s   f o r   b r o w s e   p a g e   c a l c u l a t i o n s  
 v a r   f i n C a l c P a y   =   " n / a " ;  
 v a r   f i n C a l c D e p   =   " n / a " ;  
 v a r   f i n C a l c T o t a l   =   " n / a " ;  
 v a r   f i n C a l c T e r m   =   " n / a " ;  
 v a r   f i n C a l c I n t e r e s t R a t e   =   " n / a " ;  
  
 f u n c t i o n   p a y m e n t ( )   {  
         c y c l e   + =   1 ;  
  
         / / a l e r t ( " c a l c " ) ;  
  
         / *                                  
         ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  
         '   > > >   N O T E !   -   f i e l d s   n o t   p a r t   o f   t h e   c a l c u l a t i o n   c h a i n . . . .  
         '                           m u s t   b e   e v a l u a t e d   a s   p a r t   o f   t h e   o u t p u t / c a l c / i n p u t   f i e l d s   !  
         '                           ~   o t h e r w i s e   t h e   v a l u e   w i l l   n o t   r e f r e s h  
         '  
         ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  
         * /  
         v a r   t e m p ;  
  
         / / a l e r t ( 1 ) ;                  
         t e m p   =   F 7 ( ) ;   / /   V A T   i n c l  
         / / a l e r t ( 2 ) ;  
         t e m p   =   F 1 9 ( ) ;   / /   P a y m e n t   p e r   m o n t h  
         / / a l e r t ( 3 ) ;  
         t e m p   =   F 2 2 ( ) ;   / /   S e r v i c e   F e e  
         / / a l e r t ( 4 ) ;  
         t e m p   =   F 2 3 ( ) ;   / /   P r o d u c t   I n s u r a n c e  
         / / a l e r t ( 5 ) ;  
         t e m p   =   F 2 4 ( ) ;   / /   C r e d i t   L i f e   I n s u r a n c e  
         / / a l e r t ( 6 ) ;  
  
         / /  
         / /   t h i s   i s   f o r   b r o w s e   p a g e   c a l c u l a t i o n s  
         / /  
         / / f i n C a l c P a y   =   a d d S p a c e s ( r o u n d _ d e c i m a l s (   F 1 9 ( ) ,   0   ) ) ;   / /   e x l u d e s   A d d - o n   f e e s !  
         / / f i n C a l c P a y   =   a d d S p a c e s ( r o u n d _ d e c i m a l s (   F 2 6 ( ) ,   0   ) ) ;   / /   i n l u d e s   A d d - o n   f e e s . .  
         f i n C a l c P a y   =   ( r o u n d _ d e c i m a l s (   F 2 6 ( ) ,   0   ) ) ;   / /   i n l u d e s   A d d - o n   f e e s . .  
         / / f i n C a l c D e p   =   a d d S p a c e s ( r o u n d _ d e c i m a l s (   F 1 3 ( ) ,   0   ) ) ;    
         f i n C a l c D e p   =   ( r o u n d _ d e c i m a l s (   F 1 3 ( ) ,   0   ) ) ;    
         / / f i n C a l c T o t a l   =   a d d S p a c e s ( r o u n d _ d e c i m a l s (   F 2 7 ( ) ,   0   ) ) ;   / /   i n l u d e s   A d d - o n   f e e s . .  
         f i n C a l c T o t a l   =   ( r o u n d _ d e c i m a l s (   F 2 7 ( ) ,   0   ) ) ;   / /   i n l u d e s   A d d - o n   f e e s . .  
         f i n C a l c T e r m   =   r o u n d _ d e c i m a l s (   2 4 ,   0   ) ;    
         f i n C a l c I n t e r e s t R a t e   =   r o u n d _ d e c i m a l s (   F 1 5 ( )   *   1 0 0 ,   1   ) ;    
         / /   d e b u g :  
         / / a l e r t ( f i n C a l c P a y   +   "   "   +   f i n C a l c D e p ) ;  
          
         r e t u r n   F 2 7 ( ) ;   / /   T o t a l   I n s t a l l m e n t   p a i d   o v e r   l o a n   t e r m  
  
 }  
  
 f u n c t i o n   t e s t ( )   {  
         a l e r t ( " p a y m e n t   =   "   +   p a y m e n t ( ) ) ;  
 }  
  
 / /  
 / /   n u m b e r   f u n c t i o n s  
 / /  
  
 f u n c t i o n   a d d C o m m a s ( n S t r )   {  
         n S t r   + =   ' ' ;  
         x   =   n S t r . s p l i t ( ' . ' ) ;  
         x 1   =   x [ 0 ] ;  
         x 2   =   x . l e n g t h   >   1   ?   ' . '   +   x [ 1 ]   :   ' ' ;  
         v a r   r g x   =   / ( \ d + ) ( \ d { 3 } ) / ;  
         w h i l e   ( r g x . t e s t ( x 1 ) )   {  
                 x 1   =   x 1 . r e p l a c e ( r g x ,   ' $ 1 '   +   ' , '   +   ' $ 2 ' ) ;  
         }  
         r e t u r n   x 1   +   x 2 ;  
 }  
 f u n c t i o n   a d d S p a c e s ( n S t r )   {  
         n S t r   + =   ' ' ;  
         x   =   n S t r . s p l i t ( ' . ' ) ;  
         x 1   =   x [ 0 ] ;  
         x 2   =   x . l e n g t h   >   1   ?   ' . '   +   x [ 1 ]   :   ' ' ;  
         v a r   r g x   =   / ( \ d + ) ( \ d { 3 } ) / ;  
         w h i l e   ( r g x . t e s t ( x 1 ) )   {  
                 x 1   =   x 1 . r e p l a c e ( r g x ,   ' $ 1 '   +   '   '   +   ' $ 2 ' ) ;  
         }  
         r e t u r n   x 1   +   x 2 ;  
 }  
  
 / * * 
 *   F o r m a t s   t h e   n u m b e r   a c c o r d i n g   t o   t h e    f o r m a t    s t r i n g ; 
 *   a d h e r s e s   t o   t h e   a m e r i c a n   n u m b e r   s t a n d a r d   w h e r e   a   c o m m a 
 *   i s   i n s e r t e d   a f t e r   e v e r y   3   d i g i t s . 
 *     n o t e :   t h e r e   s h o u l d   b e   o n l y   1   c o n t i g u o u s   n u m b e r   i n   t h e   f o r m a t , 
 *   w h e r e   a   n u m b e r   c o n s i s t s   o f   d i g i t s ,   p e r i o d ,   a n d   c o m m a s 
 *                 a n y   o t h e r   c h a r a c t e r s   c a n   b e   w r a p p e d   a r o u n d   t h i s   n u m b e r ,   i n c l u d i n g    $  ,    %  ,   o r   t e x t 
 *                 e x a m p l e s   ( 1 2 3 4 5 6 . 7 8 9 ) : 
 *                      0 2   -   ( 1 2 3 4 5 6 )   s h o w   o n l y   d i g i t s ,   n o   p r e c i s i o n 
 *                      0 . 0 0 2   -   ( 1 2 3 4 5 6 . 7 8 )   s h o w   o n l y   d i g i t s ,   2   p r e c i s i o n 
 *                      0 . 0 0 0 0 2   -   ( 1 2 3 4 5 6 . 7 8 9 0 )   s h o w   o n l y   d i g i t s ,   4   p r e c i s i o n 
 *                      0 , 0 0 0 2   -   ( 1 2 3 , 4 5 6 )   s h o w   c o m m a   a n d   d i g i t s ,   n o   p r e c i s i o n 
 *                      0 , 0 0 0 . 0 0 2   -   ( 1 2 3 , 4 5 6 . 7 8 )   s h o w   c o m m a   a n d   d i g i t s ,   2   p r e c i s i o n 
 *                      0 , 0 . 0 0 2   -   ( 1 2 3 , 4 5 6 . 7 8 )   s h o r t c u t   m e t h o d ,   s h o w   c o m m a   a n d   d i g i t s ,   2   p r e c i s i o n 
 * 
 *   @ m e t h o d   f o r m a t 
 *   @ p a r a m   f o r m a t   { s t r i n g }   t h e   w a y   y o u   w o u l d   l i k e   t o   f o r m a t   t h i s   t e x t 
 *   @ r e t u r n   { s t r i n g }   t h e   f o r m a t t e d   n u m b e r 
 *   @ p u b l i c 
 * /  
 / * 
 N u m b e r . p r o t o t y p e . f o r m a t   =   f u n c t i o n ( f o r m a t )   { 
 i f   ( !   i s T y p e ( f o r m a t ,    s t r i n g  ) )   { r e t u r n    ; }   / /   s a n i t y   c h e c k   
 
 v a r   h a s C o m m a   =   - 1   <   f o r m a t . i n d e x O f (  , ' ) , 
 p s p l i t   =   f o r m a t . s t r i p N o n N u m e r i c ( ) . s p l i t (  . ' ) , 
 t h a t   =   t h i s ;   
 
 / /   c o m p u t e   p r e c i s i o n 
 i f   ( 1   <   p s p l i t . l e n g t h )   { 
 / /   f i x   n u m b e r   p r e c i s i o n 
 t h a t   =   t h a t . t o F i x e d ( p s p l i t [ 1 ] . l e n g t h ) ; 
 } 
 / /   e r r o r :   t o o   m a n y   p e r i o d s 
 e l s e   i f   ( 2   <   p s p l i t . l e n g t h )   { 
 t h r o w (  N u m b e r F o r m a t E x c e p t i o n :   i n v a l i d   f o r m a t ,   f o r m a t s   s h o u l d   h a v e   n o   m o r e   t h a n   1   p e r i o d :      +   f o r m a t ) ; 
 } 
 / /   r e m o v e   p r e c i s i o n 
 e l s e   { 
 t h a t   =   t h a t . t o F i x e d ( 0 ) ; 
 }   
 
 / /   g e t   t h e   s t r i n g   n o w   t h a t   p r e c i s i o n   i s   c o r r e c t 
 v a r   f n u m   =   t h a t . t o S t r i n g ( ) ;   
 
 / /   f o r m a t   h a s   c o m m a ,   t h e n   c o m p u t e   c o m m a s 
 i f   ( h a s C o m m a )   { 
 / /   r e m o v e   p r e c i s i o n   f o r   c o m p u t a t i o n 
 p s p l i t   =   f n u m . s p l i t (  . ' ) ;   
 
 v a r   c n u m   =   p s p l i t [ 0 ] , 
 p a r r   =   [ ] , 
 j   =   c n u m . l e n g t h , 
 m   =   M a t h . f l o o r ( j   /   3 ) , 
 n   =   c n u m . l e n g t h   %   3   | |   3 ;   / /   n   c a n n o t   b e   Z E R O   o r   c a u s e s   i n f i n i t e   l o o p   
 
 / /   b r e a k   t h e   n u m b e r   i n t o   c h u n k s   o f   3   d i g i t s ;   f i r s t   c h u n k   m a y   b e   l e s s   t h a n   3 
 f o r   ( v a r   i   =   0 ;   i   <   j ;   i   + =   n )   { 
 i f   ( i   ! =   0 )   { n   =   3 ; } 
 p a r r [ p a r r . l e n g t h ]   =   c n u m . s u b s t r ( i ,   n ) ; 
 m   - =   1 ; 
 }   
 
 / /   p u t   c h u n k s   b a c k   t o g e t h e r ,   s e p a r a t e d   b y   c o m m a 
 f n u m   =   p a r r . j o i n (  , ' ) ;   
 
 / /   a d d   t h e   p r e c i s i o n   b a c k   i n 
 i f   ( p s p l i t [ 1 ] )   { f n u m   + =    .    +   p s p l i t [ 1 ] ; } 
 }   
 
 / /   r e p l a c e   t h e   n u m b e r   p o r t i o n   o f   t h e   f o r m a t   w i t h   f n u m 
 r e t u r n   f o r m a t . r e p l a c e ( / [ \ d , ? \ . ? ] + / ,   f n u m ) ; 
 } ; 
 * /  
  
 / /   n u m b e r   f o r m a t t i n g   f u n c t i o n  
 / /   c o p y r i g h t   S t e p h e n   C h a p m a n   2 4 t h   M a r c h   2 0 0 6 ,   1 0 t h   F e b r u a r y   2 0 0 7  
 / /   p e r m i s s i o n   t o   u s e   t h i s   f u n c t i o n   i s   g r a n t e d   p r o v i d e d  
 / /   t h a t   t h i s   c o p y r i g h t   n o t i c e   i s   r e t a i n e d   i n t a c t  
 f u n c t i o n   f o r m a t N u m b e r 8 ( n u m ,   d e c ,   t h o u ,   p n t ,   c u r r 1 ,   c u r r 2 ,   n 1 ,   n 2 )   {  
         v a r   x   =   M a t h . r o u n d ( n u m   *   M a t h . p o w ( 1 0 ,   d e c ) ) ;  
         i f   ( x   > =   0 )   n 1   =   n 2   =   ' ' ;  
  
         v a r   y   =   ( ' '   +   M a t h . a b s ( x ) ) . s p l i t ( ' ' ) ;  
         v a r   z   =   y . l e n g t h   -   d e c ;  
  
         i f   ( z   <   0 )   z - - ;  
  
         f o r   ( v a r   i   =   z ;   i   <   0 ;   i + + )  
                 y . u n s h i f t ( ' 0 ' ) ;  
  
         y . s p l i c e ( z ,   0 ,   p n t ) ;  
         i f   ( y [ 0 ]   = =   p n t )   y . u n s h i f t ( ' 0 ' ) ;  
  
         w h i l e   ( z   >   3 )   {  
                 z   - =   3 ;  
                 y . s p l i c e ( z ,   0 ,   t h o u ) ;  
         }  
  
         v a r   r   =   c u r r 1   +   n 1   +   y . j o i n ( ' ' )   +   n 2   +   c u r r 2 ;  
         r e t u r n   r ;  
 }  
  
 f u n c t i o n   f o r m a t _ n u m b e r ( p n u m b e r ,   d e c i m a l s )   {  
         i f   ( i s N a N ( p n u m b e r ) )   {   r e t u r n   0   } ;  
         i f   ( p n u m b e r   = =   ' ' )   {   r e t u r n   0   } ;  
         v a r   s n u m   =   n e w   S t r i n g ( p n u m b e r ) ;  
         v a r   s e c   =   s n u m . s p l i t ( ' . ' ) ;  
         v a r   w h o l e   =   p a r s e F l o a t ( s e c [ 0 ] ) ;  
         v a r   r e s u l t   =   ' ' ;  
         i f   ( s e c . l e n g t h   >   1 )   {  
                 v a r   d e c   =   n e w   S t r i n g ( s e c [ 1 ] ) ;  
                 d e c   =   S t r i n g ( p a r s e F l o a t ( s e c [ 1 ] )   /   M a t h . p o w ( 1 0 ,   ( d e c . l e n g t h   -   d e c i m a l s ) ) ) ;  
                 d e c   =   S t r i n g ( w h o l e   +   M a t h . r o u n d ( p a r s e F l o a t ( d e c ) )   /   M a t h . p o w ( 1 0 ,   d e c i m a l s ) ) ;  
                 v a r   d o t   =   d e c . i n d e x O f ( ' . ' ) ;  
                 i f   ( d o t   = =   - 1 )   {  
                         d e c   + =   ' . ' ;  
                         d o t   =   d e c . i n d e x O f ( ' . ' ) ;  
                 }  
                 w h i l e   ( d e c . l e n g t h   < =   d o t   +   d e c i m a l s )   {   d e c   + =   ' 0 ' ;   }  
                 r e s u l t   =   d e c ;  
         }   e l s e   {  
                 v a r   d o t ;  
                 v a r   d e c   =   n e w   S t r i n g ( w h o l e ) ;  
                 d e c   + =   ' . ' ;  
                 d o t   =   d e c . i n d e x O f ( ' . ' ) ;  
                 w h i l e   ( d e c . l e n g t h   < =   d o t   +   d e c i m a l s )   {   d e c   + =   ' 0 ' ;   }  
                 r e s u l t   =   d e c ;  
         }  
         r e t u r n   r e s u l t ;  
 }  
  
 f u n c t i o n   f o r m a t N u m b e r ( o b j ,   d e c i m a l )   {  
         / / d e c i m a l     -   t h e   n u m b e r   o f   d e c i m a l s   a f t e r   t h e   d i g i t   f r o m   0   t o   3  
         / / - -   R e t u r n s   t h e   p a s s e d   n u m b e r   a s   a   s t r i n g   i n   t h e   x x x , x x x . x x   f o r m a t .  
         a n y n u m   =   e v a l ( o b j . v a l u e ) ;  
         d i v i d e r   =   1 0 ;  
         s w i t c h   ( d e c i m a l )   {  
                 c a s e   0 :  
                         d i v i d e r   =   1 ;  
                         b r e a k ;  
                 c a s e   1 :  
                         d i v i d e r   =   1 0 ;  
                         b r e a k ;  
                 c a s e   2 :  
                         d i v i d e r   =   1 0 0 ;  
                         b r e a k ;  
                 d e f a u l t :               / / f o r   3   d e c i m a l   p l a c e s  
                         d i v i d e r   =   1 0 0 0 ;  
         }  
  
         w o r k N u m   =   M a t h . a b s ( ( M a t h . r o u n d ( a n y n u m   *   d i v i d e r )   /   d i v i d e r ) ) ;  
  
         w o r k S t r   =   " "   +   w o r k N u m  
  
         i f   ( w o r k S t r . i n d e x O f ( " . " )   = =   - 1 )   {   w o r k S t r   + =   " . "   }  
  
         d S t r   =   w o r k S t r . s u b s t r ( 0 ,   w o r k S t r . i n d e x O f ( " . " ) ) ;   d N u m   =   d S t r   -   0  
         p S t r   =   w o r k S t r . s u b s t r ( w o r k S t r . i n d e x O f ( " . " ) )  
  
         w h i l e   ( p S t r . l e n g t h   -   1   <   d e c i m a l )   {   p S t r   + =   " 0 "   }  
  
         i f   ( p S t r   = =   ' . ' )   p S t r   =   ' ' ;  
  
         / / - - -   A d d s   a   c o m m a   i n   t h e   t h o u s a n d s   p l a c e .  
         i f   ( d N u m   > =   1 0 0 0 )   {  
                 d L e n   =   d S t r . l e n g t h  
                 d S t r   =   p a r s e I n t ( " "   +   ( d N u m   /   1 0 0 0 ) )   +   " , "   +   d S t r . s u b s t r i n g ( d L e n   -   3 ,   d L e n )  
         }  
  
         / / - -   A d d s   a   c o m m a   i n   t h e   m i l l i o n s   p l a c e .  
         i f   ( d N u m   > =   1 0 0 0 0 0 0 )   {  
                 d L e n   =   d S t r . l e n g t h  
                 d S t r   =   p a r s e I n t ( " "   +   ( d N u m   /   1 0 0 0 0 0 0 ) )   +   " , "   +   d S t r . s u b s t r i n g ( d L e n   -   7 ,   d L e n )  
         }  
         r e t v a l   =   d S t r   +   p S t r  
         / / - -   P u t   n u m b e r s   i n   p a r e n t h e s e s   i f   n e g a t i v e .  
         i f   ( a n y n u m   <   0 )   {   r e t v a l   =   " ( "   +   r e t v a l   +   " ) " ;   }  
  
         / / Y o u   c o u l d   i n c l u d e   a   d o l l a r   s i g n   i n   t h e   r e t u r n   v a l u e .  
         / / r e t v a l   =     " $ " + r e t v a l  
         o b j . v a l u e   =   r e t v a l ;  
 }  
  
 / / a l e r t ( " - f i n C a l c M a i n . j s   -   l o a d e d   1 " ) ;  
 
