ZeroFiller ( )

Function stats

Average user rating
282
313
9999
Support
FileMaker 10.0 +
Date posted
24 June 2011
Last updated
24 June 2011
Version
Recursive function
No

Author Info
 Jasonz

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

ZeroFiller  ( Text;   Lngth;   dPlaces )


Parameters

Text  any numeric


Lngth  Length of text field


dPlaces  decimal places


Description

Tags:  Text  

To fill a zero to any numeric field.

You gonna need that if you're dealing with BNYM INFORM system..

Examples

Sample input

1.) ZeroFiller ( 123.1435; 6; 2)
2.) ZeroFiller ( "'; 5; 0)
3.) ZeroFiller ( 123456789; 11; 2)


Sample output

1.) 012314
2.) 00000
3.) 12345678900

 

Function code

Let ([
rndText = Round ( Text; dPlaces);
dotPo = Position ( Text; "."; 1; 1);
w = Lngth - dPlaces;
iLeft = If ( dotPo = 0; Text; Left (Text; dotPo - 1));
tLeft = If ( dPlaces = 0; Right ( Substitute ( 10 ^ Lngth - 1; "9"; "0") & iLeft; Lngth); Right ( Substitute ( 10 ^ w - 1; "9"; "0") & iLeft; w));
tRight = Case (
dotPo ≥ 0 and dPlaces = 0; "";
dotPo = 0 and dPlaces ≥ 1; Substitute ( 10 ^ dPlaces - 1; "9"; "0");
dotPo ≥ 1 and dPlaces ≥ 1; Left ( Right (rndText; Length (rndText) - dotPo) & Substitute ( 10 ^ dPlaces - 1; "9"; "0"); dPlaces);
""
)
];
tLeft & tRight
)

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

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

    Prototype: ZeroFiller( Text; Lngth; dPlaces )
    Function Author: Jasonz (http://www.fmfunctions.com/mid/282)
    Last updated: 24 June 2011
    Version: 1.2

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

 

Comments

comment
24 June 2011



How about:

Let ( [
n = Round ( number * 10^precision ; 0 ) ;
pad = Substitute ( 10^fixedLength - 1 ; "9" ; "0" )
] ;
SerialIncrement ( pad ; n )
)
(Edited by comment on 24/06/11 )
  General comment
comment
24 June 2011



BTW, there should be a provision for numbers exceeding the fixed length. I am not sure what is the correct result for (123456 ; 5 ; 2 ), but neither "12345600" (mine) nor "45600" (yours) seem to be it.
  General comment
Fabrice
25 June 2011



Looks a bit like http://fmfunctions.com/fname/pad which is more generic I think.
(Edited by Fabrice on 25/06/11 )
  General comment

 

 

 

 

 

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)