Shopping Cart

Search:

Signup

Contact

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

# FileMaker Pro Custom Functions

formatN ( naturalNumber ; separator )

Rate this function:

Discuss this Custom Function

Martin Spanjaard, Trias Digitaal
http://triasdigitaal.nl

formats a natural number with thousand separators

Sample Input:
 formatN( 89123456789123456789 ; "." )
Sample Output:
 89.123.456.789.123.456.789

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

## Description:

Recursive funtion to insert a separator (period or comma or whatever) between every 3 digits.
Expects a natural number, an integer > 0.

This custom function can be used as the heart of all sorts of number formatting functions, like my custom function 'formatAmount'

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:

Stupid forgot the separator in the recursion, it should be:

Let([
N = GetAsText( naturalNumber ) ;
l = Length( N )
];
Case(
l > 3
// as long as the length is greater then 3,
// keep adding a separator before(!)
// every three digits
; FormatN( Left( N ; l - 3 ) ; seprator )
& separator
& Right( N ; 3 )
// add the remaining digits to the front
// of the formatted number
; N
)
)

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

Hello,

without recursive, you can use
NumToJText ( Number ; 1; 0 ) and substitute the coma whit your separator

If you whant to control décimal you can saw this code :

Substitute (
NumToJText ( int ( nbr ) ; 1; 0 ) ; "," ; sep ) & nbr - int ( nbr )

Agnès, France
May 26, 2011 6:25am

I've modified your custom function in order to allow decimals (comma separated)
--------------------------------------------------------------- ----------------------------
Let([
D = Case ( PatternCount ( naturalNumber ; "," ) ; Right ( naturalNumber ; Length ( naturalNumber ) - Position ( naturalNumber ; "," ; 1 ; 1 ) + 1 ) ) ; // get the decimal part
N = Left ( GetAsText( naturalNumber ) ; Length ( naturalNumber ) - Length ( D ) ) ; // natural number without the decimal part
l = Length( N )
];
Case(
l > 3
// as long as the length is greater then 3,
// keep adding a separator before(!)
// every three digits
; FormatN( Left( N ; l - 3 ) ; separator )
& separator
& Right( N ; 3 ) & D // and the decimal part if it exists
// add the remaining digits to the front
// of the formatted number
; N & D // and the decimal part if it exists
)
)
// 26-05-2011, Martin Spanjaard, Trias DigitaalFormatN
// 09-11-2013, Modified by Miguel Ángel Fernández to allow natural numbers with decimals

Miguel Angel Fernández, León / Spain
November 08, 2013 7:14pm

My own version of this was the following, which I think is a bit more elegant.

FormatAmount( amount ; decimalSeparator ) =

Let(

[ sign = Case( amount < 0 ; "-" )
; amount = Abs( amount )
; separator = Case( decimalSeparator = "." ; "." ; "," )
; decimals = Right( "00" & ( Round( amount ; 2 ) * 100 ) ; 2 )
; amount = FormatN( Int( amount ) )

];
sign & amount & separator & decimals
)

// If the decimalSeparator is empty, it's a comma by default
// 26-05-2011, Martin Spanjaard, Trias Digitaal

Martin Spanjaard, Amsterdam
November 12, 2013 2:22am