0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AppleScript で 簡単カンマ入れ

Last updated at Posted at 2020-02-12

198,000 など、3桁ごとにカンマを入れるのがめんどくさかったので、ごくごく簡単に作ってみました。

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)

ハンドラで使用する場合は


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

現状では整数のみで小数点には対応していませんが、ひとまず。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?