[AppleScript]負の数値を整数にする
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | use AppleScript version "2.8" |
003 | use framework "Foundation" |
004 | use framework "AppKit" |
005 | use scripting additions |
006 | |
007 | property refMe : a reference to current application |
008 | |
009 | set numNegative to -320.5 as number |
010 | set strNegative to (numNegative) as text |
011 | set ocidNegativeString to (refMe's NSString's stringWithString:(strNegative)) |
012 | set ocidDecimalNegativeNumber to refMe's NSDecimalNumber's decimalNumberWithString:(ocidNegativeString) |
013 | set ocidNegativeOne to refMe's NSDecimalNumber's decimalNumberWithString:("-1") |
014 | set ocidAbsoluteValue to ocidDecimalNegativeNumber's decimalNumberByMultiplyingBy:(ocidNegativeOne) |
015 | log ocidAbsoluteValue's doubleValue() as number |
016 | log ocidAbsoluteValue's floatValue() as number |
017 | log ocidAbsoluteValue's stringValue() as text |
018 | |
019 | |
020 | set numNegative to -320.5 as number |
021 | if numNegative < 0 then |
022 | set numDouble to (((numNegative as number) ^ 2) ^ 0.5) as number |
023 | end if |
024 | log numDouble |
025 | |
026 | |
027 | set numNegative to -320.5 as number |
028 | if numNegative < 0 then |
029 | set strNegative to numNegative as text |
030 | set listNegativeNo to (every character of strNegative) as list |
031 | set numDouble to (text 2 thru (count of strNegative) of strNegative) as number |
032 | end if |
033 | log numDouble |
AppleScriptで生成しました |
| 固定リンク
「NSNumber」カテゴリの記事
- NSNumberのValueの考え方(2024.09.03)
- [AppleScript]負の数値を整数にする(2024.09.02)
- [NSDecimalNumber]計算にNSDecimalNumberを使う(2024.03.26)
- [小数点]小数点いかの桁揃え(2023.11.13)
- [integerValue]as integerを使わない場合(2023.01.12)
「NSDecimalNumber」カテゴリの記事
- IPアドレスを16進数に変換する(2024.11.17)
- IPアドレスを10進数に変換する(2024.11.17)
- 縦横比計算(修正 1対Xを追加)(2024.09.05)
- 小数点以下 X桁での丸め(2024.09.05)
- [AppleScript]負の数値を整数にする(2024.09.02)