it’s working fine here. You don’t give any context for your code or error. Try reworking your code as separate steps, to locate exactly where the crash is happening.
script AppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
log formatNumber_decimals_(1.23456, 2)
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
property theFormatter : missing value
on formatNumber_decimals_(n, decimals)
if my theFormatter = missing value then
set my theFormatter to current application's NSNumberFormatter's alloc()'s init()
tell my theFormatter
setLocale_(current application's NSLocale's alloc()'s initWithLocaleIdentifier_("en_US"))
setNumberStyle_(current application's NSNumberFormatterDecimalStyle)
setMinimumFractionDigits_(decimals)
setMaximumFractionDigits_(decimals)
setMinimumIntegerDigits_(1)
setRoundingMode_(current application's NSNumberFormatterRoundHalfUp)
setHasThousandSeparators_(false)
end tell
end if
set theresult to theFormatter's stringFromNumber_(n)
return theresult
end formatNumber_decimals_
end script
In the settings i have Objective-C Automatic Reference Counting set to Yes
When the line : setLocale_(current application’s NSLocale’s alloc()'s initWithLocaleIdentifier_(“en_US”)) is active then I get the following crash
First thing to do is break it down something like this:
set theLocale to current application's NSLocale's alloc()'s initWithLocaleIdentifier_("en_US")
log "After local call"
tell my theFormatter
setLocale_(theLocale)
I reported this bug to Apple.
I got an answer that the bug is a duplicate.
I suppose it was already reported by somebody else.
Now we will wait till it is solved.