FormatNumber ( )

Function stats

Average user rating
37
296
9999
Support
FileMaker 8.0 +
Date posted
06 February 2011
Last updated
07 February 2011
Version
Recursive function
No

Author Info
 Fabrice

70 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

FormatNumber  ( _number;   _thousandSep;   _precision;   _decimalSep )


Parameters

_number  well, a number or something that can be converted to a number


_thousandSep  a string


_precision  the number of decimals. If greater than the initial number of decimals, will be padded with zeros. Empty means


_decimalSep  


Description

Tags:  Text   Format  

Simple number formatting function.
WARNING : this funciton returns text, not a number (FileMaker does not need any formating when you work with numbers)

Examples

Sample input

FormatNumber ( -1234567890.123 ; " " ; 5 ; "," )


Sample output

-1 234 567 890,12300

 

Function code

/*
FormatNumber ( _number ; _thousandSep ; _precision ; _decimalSep )

by Fabrice Nordmann, 1-more-thing
http://www.1.more-thing.com

v1 - Feb 2010

Parameters :
    _number : well, a number or something that can be converted to a number
    _thousandSep : a string "," or " " for example.
    _precision : the number of decimals. If greater than the initial number of decimals, will be padded with zeros. Empty means "same as original"
    _decimalSep : "." or ",". Empty means default separator (depending on your file or system settings)

Simple number formatting function.
WARNING : this funciton returns text, not a number (FileMaker does not need any formating when you work with numbers)

*/


Let ([
    _number = 0+ GetAsNumber ( _number ) ;
    _decimalSep = Case ( IsEmpty ( _decimalSep ) ; Middle ( 3/2 ; 2 ; 1 ) ; _decimalSep ) ;
    _i = Int ( _number ) ;
    _d = Filter ( _number - _i ; 1234567890 ) ;
    _d = Case ( IsEmpty ( _precision ) ; _d ; Left ( _d & Substitute ( 10^_precision - 1 ; 9 ; 0 ) ; _precision ))
];
    Substitute ( NumToJText ( _i ; 1 ; 0 ) ; "," ; _thousandSep ) & Case ( not IsEmpty ( _d ) ; _decimalSep & _d )
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/296

    Prototype: FormatNumber( _number; _thousandSep; _precision; _decimalSep )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 07 February 2011
    Version: 1.1

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (31)
List  (28)
Date  (26)
Format  (23)
XML  (22)
Sql  (18)
Dev  (18)
Debug  (15)
Text  (13)
Layout  (13)
Interface  (13)
Variables  (12)
Filter  (11)
Design  (10)
Layout Objects  (8)
Array  (7)