6 Replies Latest reply on May 2, 2014 8:39 PM by user19752

# Can anyone tell me how I can format a number to read as follows:

I have tried everything without success and been unable to find it in the help section of FileMaker.

US Stationing; always has a + sign 2 numbers to the left.

45789 = 457+89

6890445 = 68904+45

Metric Stationing; always has a + sign 3 numbers to the left.

45789 = 45+789

6890445 = 6890+445

I would like to do this in Custom Functions

• ###### 1. Re: Can anyone tell me how I can format a number to read as follows:

First you need to format your field as text and not a number. a plus sign is not numeric.

The custom function would be:

Let([

l = Length(number);

lstr = Case (format = "US" ; left (number ; l - 2 ) ; format = "Metric"; left (number ; l - 3 ) ; "" ) ;

rstr = Case (format = "US" ; right (number ; 2 ) ; format = "Metric"; right (number ; 3 ) ; "" )

];

lstr & "+" & rstr

)

You can then call it via AddPlus( "45789" ; "US") = 457+89

etc..

• ###### 2. Re: Can anyone tell me how I can format a number to read as follows:

I did it slightly different.

/*

Station( StationNum ; SignPosition )

StationNum is your number that has no + sign.

SignPosition is the number of charactors from the right to put the + sign.

*/

Let(

[

LeftNum = Left ( StationNum ; Length ( StationNum )-SignPosition );

RightNum = Right(StationNum;SignPosition)

];

LeftNum & "+" & RightNum

)

• ###### 3. Re: Can anyone tell me how I can format a number to read as follows:

six to one, half dozen to the other

• ###### 4. Re: Can anyone tell me how I can format a number to read as follows:

To combine the best features of Mike's and Kyle's suggestions …

Stationing ( Number ; Format ) =

Let (

pos = Case ( format = "US"; 2 ; format = "Metric" ; 3 ; "Wrong format argument" ) ;

Case (

pos = 2 or pos = 3 ;

Let ( [

n = Trim ( Number ) ;

lstr = Left ( n ; Length ( n ) - pos ) ;

rstr = Right ( n ; pos )

] ;

lstr & "+" & rstr

) ;

pos

)

)

• ###### 5. Re: Can anyone tell me how I can format a number to read as follows:

Thanks!!

• ###### 6. Re: Can anyone tell me how I can format a number to read as follows:

Replace ( str ; pos ; 0 ; str2 ) insert str2 to str at pos.