Jump to content
Macro Express Forums

Padding a number with leading zeros


TGH

Recommended Posts

Hi,

 

Here is a sample of how I would approach this.

 

<TVAR2:01:02:FFFCenter:Center><TMVAR2:14:01:00:005:000:><TMVAR2:21:01:01:000:000: 0>

 

You first need to save the number to a text string variable. This example just uses the Variable Set String - Prompt for Value command. The next step uses the Variable Modify String command to pad the string. The last step also modifies the string, Replace Substring. In the Text to Replace field press the Space Bar once. In the Replace With Field enter zero (0). Check the Replace all Instances box and save.

 

So if you set the pad string option to 5, the macro will insert 4 zeroes if the original number is only one digit. If two digits, then 3 zeroes are added, etc.

Link to comment
Share on other sites

Hi,

 

Here is a sample of how I would approach this.

 

<TVAR2:01:02:FFFCenter:Center><TMVAR2:14:01:00:005:000:><TMVAR2:21:01:01:000:000: 0>

 

You first need to save the number to a text string variable. This example just uses the Variable Set String - Prompt for Value command. The next step uses the Variable Modify String command to pad the string. The last step also modifies the string, Replace Substring. In the Text to Replace field press the Space Bar once. In the Replace With Field enter zero (0). Check the Replace all Instances box and save.

 

So if you set the pad string option to 5, the macro will insert 4 zeroes if the original number is only one digit. If two digits, then 3 zeroes are added, etc.

 

 

Thanks very much that worked for me. I appreciate the help.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...