Custom Function to format number in accordance to FM Inspector

-I had got a request to show a report layout in Excel sheet , the way it is in report , by coping all the colors , fonts,conditional formatting , styling etc.
-So , we need to design an HTML that would look like the same report page on FileMaker layout and then paste the HTML to Excel sheet.

One hurdle that we can come across, is the styling of number field as we do it from FM Inspector. (styling of numbers can also be done through HTML , but this example shows how to format from FM side)

Example:- Decimal = 2 , thousand separator = ,  (setting from inspector)
For decimal =3 , the number becomes as follows:-
15.2345 = 15.234 (truncate function can achieve this)
15 = 15.000
15.1 = 15.100
15.12 = 15.120
So , for this number format conversion , i have devised a custom function ,

addingPrecision(number:precsn)
number= number to be formatted
precsn=the number of digits after decimal to be formatted.
——————————————————————————
Let (

[ data = GetAsText ( number ) ;

posnDecimal = Position ( data ; “.” ; 1 ; 1 );

len = Length ( data );

digitAfterDecimal = Middle ( data ; posnDecimal +1  ; len – posnDecimal +1 );

digitAfterDecimalTotal = Length (digitAfterDecimal);

new = Case (  IsEmpty ( data ) or data = “0” ;”0.” & repeatText ( “0” ; precsn  ; 1 );

Int ( data ) = data ; data  & “.”   & repeatText ( “0” ; precsn  ; 1 );

digitAfterDecimalTotal  ≥ precsn   ; Truncate ( data ; precsn ) ;

digitAfterDecimalTotal  < precsn   ; data & repeatText ( “0” ; precsn – digitAfterDecimalTotal ; 1 )

)

];

new
)

——————————————————————————

——————————————————————————
Supporting Custom Function:-

repeatText(txt;rept;count1)

txt = text to be repeated
rept= number of repetitions
count1 = always 1

——————————————————————————
Let (
[
// nothing requires here
];

If ( count1 = rept ;txt ; txt  & repeatText(txt;rept;count1+1) )
)
——————————————————————————

Leave a Reply