1. ginn_nezz

    Posted

    ginn_nezz
Changes in title
+applescript で 簡単カンマ入れ
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,38 @@
+198,000 など、3桁ごとにカンマを入れるのがめんどくさかったので、ごくごく簡単に作ってみました。
+
+```applescript
+set thePrice to 198000 as string
+
+set AppleScript's text item delimiters to ""
+
+set thePrice to every character of thePrice
+
+repeat with i from (count of thePrice) - 3 to 1 by -3
+ set item i of thePrice to (item i of thePrice & ",") as string
+end repeat
+
+display dialog (thePrice as string)
+```
+
+ハンドラで使用する場合は
+
+```applescript
+
+display dialog (makeComma(198000 as string))
+
+on makeComma(thePrice)
+
+ set AppleScript's text item delimiters to ""
+
+ set thePrice to every character of thePrice
+
+ repeat with i from (count of thePrice) - 3 to 1 by -3
+ set item i of thePrice to (item i of thePrice & ",") as string
+ end repeat
+
+ return thePrice as string
+
+end makeComma
+```
+
+現状では整数のみで小数点には対応していませんが、ひとまず。