# cf_num2txtSdStUO ( num ; precise ; sepDec ; sepThsd ; unit ; order )

(one more function) to format numbers with decimal and thousand separator (option)

Be the first to rate this function Log in to vote

Fabrice Ricker - Show more from this author
Kultur und Computer http://www.kultur-und-computer.de |

Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

/*

based on both fantastic cf(s) from

Agnès Barouh https://www.briandunning.com/cf/945

and

Fabrice Nordmann http://www.fmfunctions.com/functions_display_record.php?functionId=296

Salut Agnès, salut Fabrice, ça fait un bail !

Agnès Barouh, Fabrice Nordmann, Fabrice Ricker

cf_num2txtSdStUO ( num ; precise ; sepDec ; sepThsd ; unit ; order)

------- parameters ---------

num = your number

precise = decimal precision (how many cypher after the comma)

sepDec = decimal separator (f.E. "." or ",")

sepThsd = thousand separator (same as above)

unit = kg, m, €, USD, daN, whatever you want

order = > "a" will place the unit at the first place (analog to "from a to z" -> I could have taken 1, but I prefered it so)

------------ explanation --------------

~prec = Abs ( precise )

In case someone wrote a negative precision number.

Interesting for the future: negative value will round up like this: "100" would be resulting from "-2" for "112,34"

~num = 0 + GetAsNumber ( num )

In case GetAsNumber ( num ) gets no number, a zero will always be there to be formated

~int = Int ( ~num )

integer ...

~sign = Case ( ~num ≤-1 ; "" ; ~num <0 ; "-" ; "" )

case a number ist between -1 and 0, the "-" sign (integer gives a 0 back and put the comma away)

Maybe this would go right with "ceiling" and "floor", but I didn't find the time to test.

~dec = Filter ( ~num - ~int ; 1234567890 )

well, the decimal part, without separator

~rest = Case ( IsEmpty ( ~prec ) ; ~dec ; Left ( ~dec & Substitute ( 10^~prec - 1 ; 9 ; 0 ) ; ~prec ) )

I took this cool feature from Agnès and Fabrice, cool, very cool, to get exact number of "0" you want

~3 = Substitute ( NumToJText ( ~int ; 1 ; 0 ) ; "," ; ~sepThsd )

The next feature I from Agnès and Fabrice, to part the number in nice usefull 3-char-blocs from the right

And ... Of course, it's not about rounding! If you need a rounded value, round it before using the cf with the FileMaker function "round".

*/

## Comments

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.