# Commas ( Number ; Digit )

Insert commas into numbers.

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

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

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, 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, TonicNote, Inc. Sep 28, 2014 |
||

Thanks Raybaudi, you're right! I'm Japanese but I never use NumToJText function ;-) |
||

Steve Thoms, International Plastics 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 |
||

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