FormatAsPrice ( )

Function stats

Average user rating
37
94
9999
Support
FileMaker 8.0 +
Date posted
05 December 2008
Last updated
15 May 2009
Version
Recursive function
No

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

FormatAsPrice  ( _input;   _separator;   _currency;   _leading_boolean )


Parameters

_input  


_separator  


_currency  


_leading_boolean  1 means Leading, else means trailing


Description

Tags:  Interface   Format  

converts a number into a price tag

Examples

Sample input

FormatAsPrice ( ,3 ; "." ; "$" ; 1 )


Sample output

$0.30

 

Function code

/*
FormatAsPrice ( _input ; _separator ; _currency ; _leading_boolean )

By Fabrice Nordmann

v1.2, sept 2007
- handles empty parameter (zero)
v1.1, feb 2007
- _leading_boolean is renamed (was Leading_1)
- Rounded


converts a number into a price tag

notes :
_leading_boolean : 1 means Leading, else means trailing

examples :
FormatAsPrice ( ,3 ; "." ; "$" ; 1 ) = "$0.30"
FormatAsPrice ( -,329 ; "," ; " €" ; 0 ) = "-0.33 €"
*/

Let ([
_number = Round ( GetAsNumber ( _input ) ; 2 )
; _number = case ( isEmpty ( _number ) ; 0 ; _number )
; _int = Case ( Abs( _number ) >= 1 ; Int ( _number ) ; Case ( _number >= 0 ; "0" ; "-0" ))
; _dec = Filter ( Replace ( _number ; 1 ; Length ( _int ) ; "" ) ; "0123456789" )
; _dec = Left ( _dec & "00" ; 2 )
; _pos = GetAsBoolean ( _leading_boolean )
]
;
Case ( _pos = 1 ; _currency ) &
_int &
_separator &
_dec &
Case ( _pos = 0 ; _currency )
)

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

    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/94

    Prototype: FormatAsPrice( _input; _separator; _currency; _leading_boolean )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 15 May 2009
    Version: 1.3

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

 

 

 

 

 

 

 

Top Tags

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