AppleScript名:数値に対して、小数点以下の数値の切り上げ、切り下げ |
— Created 2017-08-12 by Takaaki Naganoya — Modified 2017-08-28 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSNumber : a reference to current application’s NSNumber property NSNumberFormatter : a reference to current application’s NSNumberFormatter property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp property NSNumberFormatterRoundDown : a reference to current application’s NSNumberFormatterRoundDown set a to 0.909661 set a1Res to roundingDownNumStr(a, 2) of me –> 0.9 on roundingDownNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundDown) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingDownNumStr on roundingUpNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingUpNumStr |
More from my site
(Visited 139 times, 1 visits today)