# How to turn 15000000 to 15,000,000

Hello there,

I'm having trouble figuring out how to accomplish something that seems like it should be simple. I want to change 15000000 to 15,000,000 for me. Additionally, I'd like it to check how many digits are in the number, and if there are nine digits, like in the case of 123000000, I would like it to change the number to 123,000,000. Any assistance with this would be greatly appreciated.

Thank you.

I am not at the computer to try, but maybe you could use the format option.
https://wiki.keyboardmaestro.com/token/CalculateFormat

1 Like

@JimmyHartington has the right idea. But unlike him, I am at my computer, so I made a little example to show you how formatting works. You basically just hashtags in place of integers, and whatever formatting you wish, such as comma separators and decimal points. You can even use more hashtags than necessary, as KM will automatically format it according to how many digits the integer has.

Format integers.kmmacros (7.0 KB)

Macro Screenshot (click to expand/collapse)

1 Like

Thank you to both of you. All I needed was to set a variable to itself and change the format according to your instructions. It would be great if Keyboard Maestro could allow user input for defining variables. For example, if I enter 49,000,000 for the first value and 23,000,000 for 2nd value in the user input field, I cannot add two values together.

Keyboard Maestro uses commas as array separators, so a variable containing â€ś49,000,000â€ť is treated as an array of three numbers.

However you can use underscores in numbers, so you can write it like this: â€ś49_000_000â€ť.

Hi Peter, I appreciate your response; however, Iâ€™m afraid that wonâ€™t work for me as Iâ€™ve always separated money with commas. For now, Iâ€™ll set a variable to itself and change the format using pound signs.

Then read the variable as text from the Prompt, and then use the Search and Replace action to remove the , (or replace them with _).

Thanks! Currently, I am utilizing cdthomerâ€™s solution, and it is highly effective.

Yes, that will add the commas for you. My suggestion was to help with the reverse, removing the commas so Keyboard Maestro can process it as a number.

For example, that macro, if you fed it a number containing commas, would fail to do what you want.

Thatâ€™s correct, and I am sorry for forgetting to mention that I am already doing it.

Then, Once I get the desired input from the keyboard, I use a set variable to add commas in between.

1 Like

Could you elaborate a little on the last part of the script, whatâ€™s the point of manually deleting debug variables in this way?

Edit: btw, I know the point is to delete them , but Iâ€™m wondering arenâ€™t the variables going to go out of scope and be removed automatically when the macro is done running?

Sure! Technically, thereâ€™s no such thing as a â€śdebugâ€ť variable... there are global, local and instance variables (See the Variables Wiki entry for more info). But global variables are the only kind that persist after a macro has done executing. This is valuable when building, modifying or debugging a macro because it allows you to see the variableâ€™s value even after the macro is done executing, unlike the other two kinds.

However, most of the time, I donâ€™t need to see these variables once the macro is completely built and reliable. Since I, 1) donâ€™t want to see a massive list of variables in my KM preferences window, and 2) global variables seem to slow down macro executions compared to local and instance variables, I like to convert all of my global variables to local or instance once Iâ€™ve finished building, modifying or debugging the macro.

But until that time, I sometimes use that AppleScript to delete those debug variables at the end of the macro, particularly when Iâ€™m sharing macros on the forum, because I donâ€™t want to clutter up other peopleâ€™s systems with these global variables. Prepending `debug__` to them just makes it easier to make sure I get them all deleted and donâ€™t miss any.

Just saw this part of your comment... no, `debug__` variables arenâ€™t deleted automatically, because theyâ€™re actually global variables (see the first paragraph of my initial comment).

The whole `debug__` part is just something I use to prepend a global variable for easy identification... itâ€™s nothing intrinsic to KM itself. I also use other formats to prepend variables for other purposes... for instance:

• for generic variables I want to save permanently, I use `DND__` (as do many others here)

For other variables I want to save permanently, but are used for specific cases, Iâ€™ll use things like:

• `LB__` (for my job)
• `Music__` (for music related things)
• `Finder__` (for macros that work in Finder only) etc.
1 Like