Brian Dunning's FileMaker Custom Functions

fnNumberFormat ( number ; decimals ; dec_point ; thousands_sep )

This CF simply emulates PHP's number_format() function using identical parameters (http://us2.php.net/number_format).

  Average rating: 3.9 (55 votes) Log in to vote

Drew Wesley   Drew Wesley - Show more from this author
Drewsol
https://www.drewsol.com

Share on Facebook Share on Twitter

  Sample input:
fnNumberFormat ( 12345678.9012 ; 2 ; "." ; "," )
  Sample output:
12,345,678.90

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This CF simply emulates PHP's number_format() function using identical parameters (http://us2.php.net/number_format).

 

Comments

Bruce Robertson   Bruce Robertson
May 8, 2009
What does "all rights reserved" mean in a custom function intentionally made available for copying in a custom function sharing site?
 
Drew Wesley   Drew Wesley, Drewsol
May 9, 2009
Hi Bruce,

Quite honestly, I paste this tag on all of my created CFs. Seeing that the phrase has become obsolete as of 2000, I'm removing it. However, these 'reserved rights' are what allow us to freely distribute our CFs in the first place! :)
 
Matthias Wuttke   Matthias Wuttke, Eschlikon TG
Oct 14, 2009
Hi all

I have a small add to this Function:
If I choose 0 Decimals, then I don't like for Example 35'000.
I would like to have 35'000
without a Point on the End....
Here the Solution: (only the last couple Lines
--------------------------------------------------------------------------
.
Case (
// No parameters specified...
decimals = "" AND dec_point = "" AND thousands_sep = "" ;
number ;
// No decimal requested
decimals = 0;
dollars;
// Else
dollars & dec_point & cents
)
)
--------------------------------------------------------------------------
Anyhow Bruce Thanks for this great Function!
 
Drew Wesley   Drew Wesley, Drewsol
Oct 16, 2009
Hi Matthias,

I implemented your good suggestion and made another improvement to include negative decimals - similar to the way the Round ( ) function works.
 
Vincent   Vincent, France
Feb 11, 2011
Hi,

This doesn't work with non english langauges, at least those whose native decimal separateor are not .

Your code assumes that the number have their decimal separator as a dot. If you use Filemaker on a french OS, then FMP internal decimal separator wil be the comma.

So you have to avoid this assumption in your code.

Moreover an option to avoir 129,00 when the nulber is just 129 would be nice

Thanks
 
Jon Rosen   Jon Rosen, Pembroke Pines, FL
Jan 24, 2012
Just a warning not to use this function with numbers containing leading zeros (typically stored as a text field). This function will strip leading zeros from those numbers.
 
Peter Wagemans   Peter Wagemans, Lesterius
Jul 20, 2019
middle ( pi ; 2 ; 1 ) is a good way to get the decimal separator.
 
Gerrit   Gerrit
Jul 5, 2022
This ist by far the worst CF I found on this website. It doesn't work with any FM-Version outside US or GB. It only produces a lot of BS on systems that are using comma as decimal point. For example 34,56 will become 345..56,
How ridiculous.
 

Log in to post comments.

 

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

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: