Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

decimalNumberByMultiplyingByPowerOf10:withBehavior:

INDEX>Foundation>NSDecimalNumber

10の累乗をかけて丸めた十進数オブジェクトを返します

Objective-C

- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power
                                              withBehavior:(id<NSDecimalNumberBehaviors>)behavior

Swift

func decimalNumberByMultiplyingByPowerOf10(_ power: Int16,
                              withBehavior behavior: NSDecimalNumberBehaviors?) -> NSDecimalNumber

解説

10の累乗をかけて丸めた十進数オブジェクトを返します。
レシーバが3でpowerが3なら3000を返します(3*10^3)

返り値

Objective-C

( NSDecimalNumber * )

Swift

NSDecimalNumber

十進数オブジェクト

引数

Objective-C

( short )power

Swift

_ power: Int16

累乗

Objective-C

( id <NSDecimalNumberBehaviors> )behavior

Swift

withBehavior behavior: NSDecimalNumberBehaviors?

丸め方法

クラス

NSDecimalNumber

使用可能

10.0

参照

例文

Objective-C

#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

Swift

    //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