FileMaker Custom Function - Formating Bytes
I recently had a need to format a field that was logging bytes into a database of files.
The custom function has two (2) dependancies:
1.) MinValue ( theList; treatAsNumeric ) URL: http://www.briandunning.com/cf/1566
2.) MaxValue (theList; treatAsNumeric ) URL: http://www.briandunning.com/cf/1565
Custom Function:
formatBytes ( bytes; precision )
Let ([ units = "B¶KB¶MB¶GB¶TB¶PB¶EB¶ZB¶YB"; newBytes = MaxValue ( bytes & "¶0"; 1); pow = Floor ( If ( newBytes; Ln ( newBytes ) / Ln ( 1024 ); 0 ) ); selUnit = MinValue ( pow & "¶" & (ValueCount ( units ) -1 ); 1); result = newBytes / (1024^selUnit) ]; Round ( result ; precision ) & " " & GetValue ( units ; selUnit + 1 ) )
This function will take a byte value and convert it to the appropriate order of magnitude, while selecting the byte value.










