How to Format Numbers Returned From an API Call


I’m building a new macro which parses the JSON response of an API to extract a numeric value. My problem is, the JSON doesn’t format the value consistently and will truncate the decimals when they are zeros (e.g. 23.1, 42), but I always want two decimal places consistently (e.g. 23.10, 42.00).

I searched in the forum and saw you could format numbers using “Set Variable to Calculation” and format formulas using the “CalculateFormat” token, but I couldn’t get either to format a variable.

I realize this could most likely be solved via scripting, but a straightforward solution would be more desirable to me.

How can I achieve my goal, if possible? Thank you in advance! :smiley:

Use CalculateFormat, but with a very simple "formula" that's just the variable. Like this:

Format Variable.kmmacros (1.5 KB)

Note that when you're inside %CalculateFormat%% you don't use %Variable%VarName% to refer to variables, just VarName itself.


Hello and thank you for the help. Dr. Drang!

This was exactly what I was missing, I was still using %Variable%VarName% inside.


You can also do something like this:

Keyboard Maestro Actions.kmactions (718 B)
Keyboard Maestro Export