Jump to content

Break number into groups of 4 digits


This topic is 1656 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I'm looking for a field calculation that will break a number into groups of 4 digits, each group separated by a space. The number can have 5 or more digits (say up to 16). For example:

XXXXXXXXXXXXXXXX  to  XXXX XXXX XXXX XXXX

Link to comment
Share on other sites

Strictly speaking, this is a looping calculation and requires either a recursive custom function or the While() function. However, if the input is limited to 16 digits or less, you could settle for a simple:

Trim ( 
Left ( Yourfield ; 4 )
& " " &
Middle ( Yourfield ; 5 ; 4 )
& " " &
Middle ( Yourfield ; 9 ; 4 )
& " " &
Middle ( Yourfield ; 13 ; 4 )
)

or, if you prefer:

Trim ( 
Replace ( Replace ( Replace (
Yourfield ; 
13 ; 0 ; " " ) ;
9 ; 0 ; " " ) ;
5 ; 0 ; " " )
)

This is assuming that the grouping should start from left - so that an input of 1234567890 will return "1234 5678 90".

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

1 hour ago, Steve Martino said:

Genius on the 'Replace' (well to me.  To you it's just another day :) )

Actually, I stole it from here:
https://fmforums.com/topic/32095-how-to-format-a-numerical-field-to-show-as-smpte/?do=findComment&comment=145473

 

 

1 hour ago, Steve Martino said:

How would it look with the While ( ) function?

It could be =

While ( [ 
text = Yourfield ; 
start = 5
] ; 
start ≤ Length ( text ) ; 
[ 
text = Replace ( text ; start ; 0 ; " " ) ;
start = start + 5
] ; 
text 
)

 

  • Like 1
Link to comment
Share on other sites

This topic is 1656 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.