AppleScript名:数値書式関連 |
use AppleScript version "2.4" use framework "Foundation" use scripting additions set theNumber to 1.234567890123E+12 set theResult to formatNumber_(theNumber) –> "1,234,567,890,123" set aRes to textFromNumber_forLocale_(1.2345678E+4, "fr") –> "douze-mille-trois-cent-quarante-cinq virgule six sept huit" set aRes to textFromNumber_forLocale_(1.2345678E+4, "ja") –> "一万二千三百四十五・六七八" set aRes to formatNumber_usingFormat_(1.2345678E+4, "#,###.00;0.00;(#,##0.00)") –> "12,345.68" on formatNumber:theNumber set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterDecimalStyle) set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber: on textFromNumber:theNumber forLocale:localeString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterSpellOutStyle) set theLocale to current application’s NSLocale’s localeWithLocaleIdentifier:localeString theFormatter’s setLocale:theLocale set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end textFromNumber:forLocale: on formatNumber:theNumber usingFormat:formatString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setFormat:formatString theFormatter’s setLocalizesFormat:false set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber:usingFormat: |
More from my site
(Visited 29 times, 1 visits today)