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: 4.0 (54 votes) Log in to vote

Andrew Butt   Andrew Butt
Drewsol
http://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, Los Angeles, CA
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, Los Angeles, CA
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.
 

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.

Under construction. Email me your wish list for improvements.