INDEX>Foundation>NSDecimalNumber
10の累乗をかけて丸めた十進数オブジェクトを返します
- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power withBehavior:(id<NSDecimalNumberBehaviors>)behavior
func decimalNumberByMultiplyingByPowerOf10(_ power: Int16, withBehavior behavior: NSDecimalNumberBehaviors?) -> NSDecimalNumber
解説
10の累乗をかけて丸めた十進数オブジェクトを返します。
レシーバが3でpowerが3なら3000を返します(3*10^3)
引数
( short )power
_ power: Int16
累乗
( id <NSDecimalNumberBehaviors> )behavior
withBehavior behavior: NSDecimalNumberBehaviors?
丸め方法
フレームワーク
Foundation
クラス
NSDecimalNumber
使用可能
10.0
参照
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSNumberFormatter *numFormat = [[NSNumberFormatter alloc] init] ; NSDecimalNumber *dNum1 = [[[NSDecimalNumber alloc] initWithString:@"3"] autorelease]; NSDecimalNumber *dNum = [NSDecimalNumber alloc] ; dNum = [dNum1 decimalNumberByMultiplyingByPowerOf10:3 withBehavior:[NSDecimalNumber defaultBehavior]]; [numFormat setMaximum:dNum]; [numFormat setPositiveFormat:@"#,##0.00"]; [myOutlet setFormatter:numFormat]; NSLog([NSString stringWithFormat:@"%.2f",[[numFormat maximum] doubleValue]]); } @end
//NSDecimalNumber decimalNumberByMultiplyingByPowerOf10:withBehavior: @IBAction func function021(sender: AnyObject) { let dNum1 : NSDecimalNumber = NSDecimalNumber(string: "2") let dNum2 : Int16 = 3 let dNum : NSDecimalNumber = dNum1.decimalNumberByMultiplyingByPowerOf10(dNum2, withBehavior: NSDecimalNumber.defaultBehavior()) let numFormat : NSNumberFormatter = NSNumberFormatter() numFormat.minimum = dNum //最小値が2*10^3=2000 numFormat.positiveFormat = "#,##0.00" textField.formatter = numFormat NSLog("function014") commentLabel.stringValue = "←最小値が2*10^3=2000" }
編集時のバージョン
OS X 10.11
Swift2.0