
To summarise all of this, here’s one possible re-working of your script that incorporates the stuff above: to setDecimalPlaces for N to d as integer : 2
#MAC GEEKTOOL HOW TO#
This doesn’t mean you can’t use these terms or assign things to them but you need to know when you can do this, and how to do it appropriately. You should be able to tell it’s a special word because, when you compile the script in Script Editor, it will appear in a specific font and colour that differentiates it as a being a pre-defined term. To this: tell application "JSON Helper" to fetch JSON from " tell state of resultĪs you will see, assigning something to the variable result is, at best, unnecessary, and in other cases, not a good idea, as result is a property in AppleScript that will always contain the output of the most recently executed line of a script. Set result to (fetch JSON from " tell state of result Lastly, I’d suggest changing this: tell application "JSON Helper" It’s not necessarily the best example of AppleScript’s so-called “natural language syntax”, so you might prefer to stick with the arithmetic. However, AppleScript is also familiar with various temperature scales, so it can perform the conversion for you if you prefer: set officeTempF to (officeTemp / 100) as degrees Celsius as degrees Fahrenheit as number To make the arithmetic less ambiguous to a casual reader, I would have written it like this: set officeTempF to (officeTemp / 100) * (9 / 5) + 32 You have a line in your script that converts a temperature value from Celsius to Fahrenheit: set officeTempF to (officeTemp / 100 * 9 / 5 + 32) Your number_to_string() handler, which seems to be there to cater for numbers expressed using scientific notation, is, therefore, superfluous, since AppleScript understands scientific notation already. Additionally, the "to" parameter is optional, and current is set to use 2 as the default value if omitted.

You’ll notice that both parameters can accept a number or a string representation of a number, including one in scientific notation. It can be called in any of the following ways: setDecimalPlaces for 123.456543 to "2" Set x to (round N * k rounding as taught in school) / k Here’s an alternative method that’s shorter, faster, and less likely to error: to setDecimalPlaces for N to d as integer : 2

So, passing it number 123.456543 and specifying the number of decimal places as 3 returns 123.457, whilst specifying the number of decimal places as 4 returns 123.4565. From what I can tell, your round_truncate() AppleScript handler outputs a number to a specified number of decimal places.
