Simple Calculations Fail Every Time Been Stuck for Weeks... (v10.0.2)

I'm using an execute Javascript action to pull a price (formatted like 46,869.20) from a field on Bybit.com and setting it to a variable.

Then, I need to subtract a second variable (currently 900) from the first and set the result to a third variable. However, the "Set Variable to Calculation" action fails every time I try to do any calculations which include the variable coming from a Chrome field using .innerText.

Feels like I've tried everything. This has seriously been going on for weeks.

I'm on MacOS Monterey 12.2

TEMP Tests.kmmacros (4.6 KB)

What kind of failure is in the Engine log? (Help > Open Logs Folder > Engine.log)

It sounds like KM is not interpreting the result as a number based on whatever that query sends back.

Maybe trim PriceMark whitespace?

Assuming the JavaScript step is working, the problem is going to be with the "number" stored in PriceMark. It's actually being stored as a string. Keyboard Maestro will convert it to a number in the Calculation step if it can, but the comma is preventing the conversion. Keyboard Maestro, like lots of languages, cannot parse numbers with commas.

The solution is to use a Search and Replace action to get rid of the commas in the variable PriceMark before the Calculation step.

1 Like