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  (31 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.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

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 9 + 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. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions