Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



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

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

formatN ( naturalNumber ; separator )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.5  (32 votes)
  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

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 8 + 2 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. HexUUIDToNum_cf (_uuid)
  (Sat, Jun 16, 1:55pm)
2. httpResponseCode ( responseHeaders )
  (Tue, Jun 12, 10:40pm)
3. FindDuplicateCharacters ( string )
  (Fri, Jun 08, 5:01pm)
4. FieldRepetitionLast ( field ; maxRepetition )
  (Wed, Jun 06, 6:05pm)
5. CountModifiedRecords ( NameTimestampField ; StartTimestamp ; EndTimestamp )
  (Mon, May 28, 8:23am)
6. JSONArrayLength ( JSONArrayStr )
  (Fri, May 25, 7:46am)
7. interpolation (y1; y2; y3; x1; x2; x3; x1y1; x2y1; x1y2; x2y2; rnd)
  (Sat, May 19, 3:55am)
8. @JSONFormatElements ( json )
  (Tue, May 15, 3:31am)

RSS Feed of Custom Functions