An official Batch Programming blog! To Solve the daily problems with windows and fixing them with little notepad scripts. Unlock the Hidden Secrets of Windows, Learn to crack Software via CMD & Make your own Programming tools. Understand to Manipulate your PC via CMD.

Convert Numbers to Words with CMD – IntToStr by Sintrode

CONVERT NUMBERS TO WORDS with CMD: Scripts don’t always have to be useful. Sometimes you just want a toy to play with, or you just want to see what a language can do. Sometimes you just feel like entering a contest about turning integers into words.

Requirement for BATHAT challenge, May 2020

This script was written for the May 2020 BatHat contest.

What is IntToStr? – CONVERT NUMBERS TO WORDS

IntToStr is a script that converts integers to their word equivalents. 1000 becomes one thousand, 256 becomes two hundred and fifty-six, and so forth. Coming in at just over 6KB, this script is mostly comments and some hard-coded arrays. A previous version of the script dynamically generated the arrays, but the script took three times as long to run.

When in doubt, use brute force.

Ken Thompson

Features of IntToStr by Sintrode

To convert numbers to words – The script starts with basic user input to confirm that an integer was actually provided. Once it’s been determined that one was, the script breaks the number into chunks of three digits, and the highest power of 1000 is determined. The number is then printed one chunk at a time with its corresponding power of 1000.

Project Explanation By Sintrode

How To Use IntToStr – CONVERT NUMBERS TO WORDS

IntToStr takes an integer as an argument and displays the word equivalent. If no argument is provided, the script exits immediately.

Call IntToStr.bat [Number]
CONVERT NUMBERS TO WORDS
IntToStr in Action

There are no plans at this time to add a set /p command to allow for user input that way; this is a command-line tool and should be treated as one. That means that you can use this as a batch function in your projects.

Performance Analysis – IntToStr by Sintrode

IntToStr can handle integers up to sixty-six digits long. A number this big takes about 330 milliseconds to display. A simple five-digit number takes around 100 milliseconds to display. (Of course, this will vary based on your PC’s specs.)

If the script is revisited in the future, a help screen will be included if invalid input is provided, and the code to validate that user input is actually a number will handle dashes better – right now, the script thinks that 123-456 is a valid number and is read “one million two hundred thirty- thousand four hundred and fifty-six.

Instead of just checking that user input contains a string consisting of numbers and a dash, a better algorithm would be to remove the first dash if one exists and then check that the remaining substring consists solely of numbers.

From The Editor’s Desk

If you have any ideas for practical uses for this script, comment below or leave a message on either our Discord or Whatsapp.

SHA-256 Checksum For Verification - 
9ec61cef189e42b5d1010c83c680228f47837c883402952eeea0adf3c1f30929

Keep learning, keep sharing….
Be happy, spread happiness…

TheBATeam

Download Link

Next Post

Previous Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2020 TheBATeam

Our Core Values   /   Terms & Conditions   /   Privacy Policy   /   Why Register?

Theme by Anders Norén