问题描述
我想要一种基于区域设置返回当前小数和千位分隔符的方法。我知道您可以使用locale decimal_point
和locale thousands_sep
获取基于语言的分隔符,并且如果设置了自定义分隔符,则可以使用defaults read -g AppleICUNumberSymbols
,但我找不到返回的方法基于区域的值。
例如,在“语言和区域系统偏好设置”页面中,首选语言设置为英语,而“区域”设置为法国。我想要的东西将为千位分隔符返回“”,为十进制分隔符返回“,”。
解决方法
好的,所以根据Larme对Foundation.framework的建议,我提出了以下解决方案,该解决方案将为我提供使用osascript访问NSNumberFormatter的shell脚本中想要的东西:
osascript -e 'use framework "Foundation"' -e 'return (decimalSeparator of init() of alloc() of NSNumberFormatter of current application as string)'