AppleScript名:数値の桁数を求める v2 |
— Created 2014-12-04 by Takaaki Naganoya — 2014 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use bPlus : script "BridgePlus" set aList to {} set aRes to 0 repeat with i from 1 to 9999 by 1 set d to getDigit(i) of me if aRes is not equal to d then set the end of aList to {i, d} set aRes to d end if end repeat aList –> {{1, 1}, {10, 2}, {100, 3}, {1000, 4}} –数値の桁数を求める(マイナスの数は想定外) on getDigit(aNum as integer) load framework set b to ((current application’s SMSForder’s log10ValueOf:aNum)) set c to b as real set d to round c rounding down return (d + 1) end getDigit |
BridgePlusがmacOS 10.15以降でうまく動かない環境もあるので、数値演算ライブラリcalcLibASを呼び出すものも掲載しておきます。
AppleScript名:数値の桁数を求める v3.scpt |
— – Created by: Takaaki Naganoya – Created on: 2020/06/30 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" use scripting additions use framework "Foundation" use calSub : script "calcLibAS" –http://piyocast.com/as/asinyaye set aRes1 to getNumDigit(-9999) of me –> 3 set aRes2 to getNumDigit(100) of me –> 2 on getNumDigit(aNum) set a2Val to abs aNum return round (log10 a2Val) rounding down end getNumDigit |
More from my site
(Visited 58 times, 1 visits today)