AppleScript名:日本語的数値表現エンコーダーv2 |
–課題:オーバーフローチェックを行っていない set a to "102320120000108220010" set jRes to encodeJapaneseNumText(a) of japaneseNumberEncodingKit –> "1垓232京120兆1億822万10" script japaneseNumberEncodingKit –数字文字列を日本語数値表現文字列に変換 on encodeJapaneseNumText(aNum) set aText to Stringify(aNum) of me set aText to aText as Unicode text set dotText to "." as Unicode text set upperDigit to "" set lowerDigit to "" –小数点の処理 if dotText is in aText then set b to offset of dotText in aText set upperDigit to characters 1 thru (b – 1) of aText set upperDigit to upperDigit as Unicode text set lowerDigit to characters b thru -1 of aText set lowerDigit to lowerDigit as Unicode text else set upperDigit to aText end if set scaleList3 to {"", "万", "億", "兆", "京", "垓", "丈", "壌", "溝", "砂", "正", "載", "極", "恒河沙", "阿僧梢", "那由他", "不可思議", "無量大数"} set splitDigit to 4 set nList to splitByDigit(upperDigit, splitDigit) of me set nList to reverse of nList set resText to "" set digCount to 1 repeat with i in nList set b to (contents of i) as number if b is not equal to 0 then set resText to (b as text) & item digCount of scaleList3 & resText end if set digCount to digCount + 1 end repeat return resText & lowerDigit end encodeJapaneseNumText –指定桁数で区切る on splitByDigit(a, splitDigit) set aList to characters of a set aList to reverse of aList log aList set resList to {} set tempT to "" set tempC to 1 repeat with i in aList set tempT to contents of i & tempT if tempC mod splitDigit = 0 then set resList to {tempT} & resList set tempT to "" end if set tempC to tempC + 1 end repeat if tempT is not equal to "" then set resList to {tempT} & resList end if resList end splitByDigit on Stringify(x) — for E+ numbers set x to x as string set {tids, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, {"E+"}} if (count (text items of x)) = 1 then set AppleScript’s text item delimiters to tids return x else set {n, z} to {text item 1 of x, (text item 2 of x) as integer} set AppleScript’s text item delimiters to tids set i to character 1 of n set decSepChar to character 2 of n — "." or "," set d to text 3 thru -1 of n set l to count d if l > z then return (i & (text 1 thru z of d) & decSepChar & (text (z + 1) thru -1 of d)) else repeat (z – l) times set d to d & "0" end repeat return (i & d) end if end if end Stringify end script |
More from my site
(Visited 34 times, 1 visits today)