Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

insert_commas ( number )

Rate this function:

Discuss this Custom Function

Matthew Stetson, Antidote Solutions
http://www.antidotesolutions.com

Insert commas in a number

Sample Input:
 Insert_Commas ( 1000000 )
Sample Output:
 1,000,000

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

Inserts commas before every third digit before a decimal point. Uses recursion to handle any number, including negative values and decimals.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

## Discuss:

this work around resolved issue

Case(
Int( number ) <> number;
Insert_Commas( Int( number ) ) & GetAsText( Abs( number ) - Abs( Int( number ) ) );
Length( number ) > 3;
Insert_Commas( Left( number; Length( Substitute ( number ; "," ;"" ) ) - 3 ) ) & "," & Right( Substitute ( number ; "," ;"" ); 3 );
number
)

thom droz, Fort Lauderdale
November 30, 2010 10:17am

Just uploaded my function formatN, which does the more or less the same as yours, and works more or less in the same way, but is easier to read.
Forms the kernel of my other function formatAmount.

formatN( naturalNumber, separator ) =

Let([
N = GetAsText( naturalNumber ) ;
l = Length( N )
];
Case(
l > 3
; FormatN( Left( N ; l - 3 )) & separator & Right( N ; 3 )
; N
)
)

Martin Spanjaard, Amsterdam, the Netherlands
May 26, 2011 6:01am

what if i wanted to use numbers in this format

10,00,00,000

?????

pls show some way..using fmp12 adv

indiguy, india
January 11, 2014 1:41pm

Most of these functions screw up if the input is text and contains either a user-entered comma or ".00" at the end (in the case you're passing a dollar amount). This one is more thorough and should work with any format of a number:

f_commas ( number )

Let ( [
nums = "0123456789" ;
p = Position ( number ; "." ; 1 ; 1 ) ;
p = If ( p <= 0 ; Length ( number ) + 1 ; p ) ;
p2 = Position ( number ; "," ; 1 ; 1 ) ;
p = If ( p2 > 0 ; p2 ; p ) ;

n1 = Middle ( number ; p - 1 ; 1 ) ;
n2 = Middle ( number ; p - 2 ; 1 ) ;
n3 = Middle ( number ; p - 3 ; 1 ) ;
n4 = Middle ( number ; p - 4 ; 1 )
] ;

If (
p > 4 and Exact ( Filter ( n1 ; nums ) ; n1 ) and Exact ( Filter ( n2 ; nums ) ; n2 ) and Exact ( Filter ( n3 ; nums ) ; n3 ) and Exact ( Filter ( n4 ; nums ) ; n4 ) ;
f_commas ( Left ( number ; p - 4 ) & "," & Middle ( number ; p - 3 ; 99999999 ) ) ;
number
)
)

Chris Bishop, Los Angeles
March 14, 2017 12:31pm

More concise version (plus can choose 2, 3, 4 digits per comma):

f_commas ( number ; spacing )

Let ( [
nums = "0123456789" ;
p = Position ( number ; "." ; 1 ; 1 ) ;
p = If ( p <= 0 ; Length ( number ) + 1 ; p ) ;
p2 = Position ( number ; "," ; 1 ; 1 ) ;
p = If ( p2 > 0 ; p2 ; p ) ;

n = Middle ( number ; p - (spacing + 1) ; (spacing + 1) )
] ;

If (
p > (spacing + 1) and Exact ( Filter ( n ; nums ) ; n ) ;
f_commas ( Left ( number ; p - (spacing + 1) ) & "," & Middle ( number ; p - (spacing) ; 99999999 ) ; spacing ) ;
number
)
)

Chris Bishop, Los Angeles
March 14, 2017 1:24pm