JavaScript Number to AppleScript

Here is a example showing if we like to have fixed number from JavaScript we could
use toFixed(1…20) to convert it to AppleScript we need to declare it as string.
If we use AppleScripts real it will not work or doubleValue().

From Mozilla: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
We could read ‘toFixed’() return a string.

Only like to point it out because the result could be wrong.

ex.

use framework "Foundation"
use framework "JavaScriptCore"
use scripting additions

set theScript to "function myFunction() {
var amount = 100.12345;
return amount.toFixed(2);
}
myFunction()
"
set theNumber to runJavaScript(theScript) as string
set theNumber to (first word of theNumber) as real
-- or
set theNumber to runJavaScript(theScript) as string
set theNumber to (run script theNumber) as real
-- or
set theNumber to runJavaScript(theScript)
set theNumber to (theNumber's valueForKey:"doubleValue") as real

class of theNumber

on runJavaScript(_theScript)
	set theJSContext to current application's JSContext's new()
	set theEvaluateScript to (theJSContext's evaluateScript:_theScript)'s toObject()
end runJavaScript
use framework "Foundation"
use framework "JavaScriptCore"
use scripting additions

set theNumber to numberWithDecimal("100.12345", "3")
set theNumber to (theNumber's valueForKey:"doubleValue") as real

on numberWithDecimal(_number, _decimal)
	set jsString to "function n() {var num = " & _number & ";return num.toFixed(" & _decimal & ")} n()"
	set theJSContext to current application's JSContext's new()
	set theEvaluateScript to (theJSContext's evaluateScript:jsString)'s toObject()
end numberWithDecimal