ACF Library

NumFormat

Back to List

Description: Formats a given number with 1000 separators and two decimals.

FileMaker Prototype:

Set Variable [$res; ACFU_NumFormat( float_num;  string_comma)]

Category: BOOTSTRAP

NOTE: The bootstrap library comes preloaded in the plugin. Read more

Function source:

/*

   Number Formatting - with comma and thousand-group separator.
   A fixed space " " is used as the thousand separator.
   Example from FileMaker calculation: ACFU_NumFormat(amount, ",")
   Where the amount is 12345.2 => 12 345,20
   
*/
function NumFormat  ( float num, string comma ) 
   functionID 230; 
   string sNum; 
   if ( comma != ".") then
      sNum = substitute ( format ( "%.2f", num ), ".", comma ) ;  
   else
      sNum = format ( "%.2f", num ); 
   end if
   
   return regex_replace ( "\d{1,3}(?=(\d{3})+(?!\d))", sNum, "$& ") ;  
   
end

NumFormat give you 1000 separators for a given number. This is especially useful when you need numers in merge-fields in a FileMaker layout. As it is hard do specify number format on merge fields.

It uses a regex formula to do the formatting, See reference to it here

Example

Set Variable [$$OrderSum; "Total for this order: " & ACFU_NumFormat( Orders::total;  ".")]
Then in a merge field: <<$$OrderSum>>

Shown on Order: 
Total for this order: 200 443.50

If you intend to use "," as thousand separator instead of space, you can copy the function, give it some other name and change the function ID to something unique outside the are 200-300. Then you can edit the regex_replace line in the function. Having comma as 1000 separators, makes us stick with period as decimal separator, so that parameter is not needed.

Example

function NumFormatComma  ( float num ) 
    functionID 712; 
    string sNum = format ( "%.2f", num ); 
    return regex_replace ( "\d{1,3}(?=(\d{3})+(?!\d))", sNum, "$&,") ;  
end

Compile it and use it like this:

Set Variable [$$OrderSum; "Total for this order: " & ACFU_NumFormatComma( Orders::total)]
Then in a merge field: <<$$OrderSum>>

Shown on Order: 
Total for this order: 200,443.50
Back to List