AnsweredAssumed Answered

Help please with custom function

Question asked by sherab4 on Oct 12, 2017
Latest reply on Oct 13, 2017 by sherab4

I copied a custom function from a link I received in a previous query.

 

/*

Function:

FormatNumberAsText ( number ; currency ; separator ; decimal ; precision )

 

 

Parameters:

number = the number you want to format

currency = the string that identifies the currency or is a prefix -

optional

separator = the punctuation that breaks up big numbers - optional

decimal = the punctuation that separates integer digits from fraction digits

          It defaults based on FMP's localization unless rounding is <= 0,

          in which case it's omitted

precision = number of places for rounding - defaults to 2 if parameter is

          not a digit or is unspecified

Purpose:

This function formats numbers for use in text strings or calculations with a

text result. It's especially useful when there are multiple numbers in a

text string and at least one must be displayed in a different format than

the others.

Notes:

Could expand to include colorization parameter (for negative numbers)

Could expand to include choice of negative symbology for numbers < 0

Could expand to include trailing/leading parameter for currency notation

 

*/

Let ( [

t = Int ( GetAsNumber ( 2 ) ) ;

prec = Case ( Length ( t ) ; t ; 2 ) ;

dec = Case ( Length ( 0 ) ; 0 ; Filter ( 1/2 ; ".," ) ) ;

n = Round ( 2 + 0 ; prec ) ;

sgn = Case ( n < 0 ; "-" ) ;

n = Abs ( n );

x = NumToJText ( Int ( n ) ; 1 ; 0 ) ;

y = NumToJText ( n * 10^prec ; 0 ; 0 )

] ;

 

 

sgn & $

& Substitute ( x ; "," ; 0 )

& Case (

prec > 0 ;

dec & Right ( 10^prec & y ; prec )

)

 

 

)

 

But I get an error message when I add it to a calculation. doesn't seem to make any difference if I add the figure or the field name. See attached screen capture.

Outcomes