Brian Dunning's FileMaker Custom Functions

Commas ( Number ; Digit )

Insert commas into numbers.

  Average rating: 4.7 (22 votes) Log in to vote

Koji Takeuchi   Koji Takeuchi - Show more from this author
TonicNote, Inc.
https://tonic-note.com

Share on Facebook Share on Twitter

  Sample input:
Commas ( 1234.56 ; 3 )
  Sample output:
"1,234.56"

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

Commas ( Number ; Digit )
2014.09.26, Koji Takeuchi

description:
Insert commas into numbers.
Params:
Number Numbers you are about to add commas.
Digit Digit number for comma insertions.
Default is 3.
Example:
Commas ( 123456 ; 3 )
-> "123,456"
Commas ( 1234.56 ; 3 )
-> "1,234.56"

Commas ( 123456 ; "" ) = Commas ( 123456 ; 3 )
Commas ( "" ; "?" ) will show this help.

 

Comments

Raybaudi   Raybaudi, Rome
Sep 28, 2014
The built in FMP function:

NumToJText ( number ; 1 ; 0 )

inserts a comma every 3 digit, so NumToJText ( 1234.56 ; 1 ; 0 ) returns 1,234.56
 
Koji Takeuchi   Koji Takeuchi, TonicNote, Inc.
Sep 28, 2014
Thanks Raybaudi, you're right!
I'm Japanese but I never use NumToJText function ;-)
 
Steve Thoms   Steve Thoms, Norwich, VT
Dec 8, 2015
This CF fails if the number submitted is a negative number whose absolute value has a length that is a multiple of the Digit, i.e. -107 is returned as 0,107.

I have corrected this using the code here:

(This code starts after the declaration of the MSG variable)

CHECK =
GetAsNumber ( Number ) ;
SIGN =
If ( CHECK < 0 ; "-" ; "" ) ;
SOURCE =
Abs ( GetAsNumber ( Number ) ) ;
DIGIT =
Case (
not IsEmpty ( GetAsNumber ( Digit ) ) ;
GetAsNumber ( Digit ) ;
3
) ;
SPLIT =
Substitute ( GetAsText ( SOURCE ) ; "." ; ¶ ) ;
INTVAL =
GetValue ( SPLIT ; 1 ) ;
DECIMAL =
GetValue ( SPLIT ; 2 ) ;
CURRENT =
Right ( INTVAL ; DIGIT ) &
Case (
not IsEmpty ( DECIMAL ) ;
"." & DECIMAL
) ;
REST =
Left ( INTVAL ; Length ( INTVAL ) - DIGIT )
] ;

Case (
ERROR ;
MSG ;

Length ( INTVAL ) > DIGIT ;
Commas ( SIGN & REST ; DIGIT ) & "," & CURRENT ;
SIGN & SOURCE
)
)

I hope this helps,

Steve
 

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 15 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: