macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

initWithMantissa:exponent:isNegative:

INDEX>Foundation>NSDecimalNumber

十進数オブジェクトを仮数、ベキ指数で初期化して返します

Objective-C

- (instancetype)initWithMantissa:(unsigned long long)mantissa
                        exponent:(short)exponent
                      isNegative:(BOOL)flag

Swift

convenience init(mantissa mantissa: UInt64,
        exponent exponent: Int16,
      isNegative flag: Bool)

解説

十進数オブジェクトを仮数、ベキ指数で初期化して返します。
±(mantissa*10^exponent)

mantissa = 3
exponent = 2
isNegative =false
のとき、3*10^2 = 300

mantissa = 5
exponent = 2
isNegative =false
のとき、5*10^2 = 500

mantissa = 3
exponent = 3
isNegative =false
のとき、3*10^3 = 3000

返り値

Objective-C

( instancetype )

Swift

NSDecimalNumber

十進数オブジェクト

引数

Objective-C

( unsigned long long )mantissa

Swift

mantissa mantissa: UInt64

仮数

Objective-C

( short )exponent

Swift

exponent exponent: Int16

ベキ指数

Objective-C

( BOOL )flag

Swift

isNegative flag: Bool

正、負

クラス

NSDecimalNumber

使用可能

10.0

参照

例文

Objective-C

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSNumberFormatter *numFormat = [[NSNumberFormatter alloc] init] ;
NSDecimalNumber *dNum = [[[NSDecimalNumber alloc] autorelease] initWithMantissa:32
                                            exponent:3
                                            isNegative:NO
                                            ];


[numFormat setMaximum:dNum];
[numFormat setPositiveFormat:@"#,##0.00"];
[myOutlet setFormatter:numFormat];

NSLog([NSString stringWithFormat:@"%.2f",[[numFormat maximum] doubleValue]]);
}

@end

Swift

    //NSDecimalNumber initWithMantissa:exponent:isNegative:
    @IBAction func function006(sender: AnyObject) {
        let dNum : NSDecimalNumber =
        NSDecimalNumber(mantissa: 3,
            exponent: 2,
            isNegative: false ) //3*10^2 = 300
        let numFormat : NSNumberFormatter = NSNumberFormatter()
        numFormat.minimum = dNum    //最小値が
        numFormat.positiveFormat = "#,##0.00"
        textField.formatter = numFormat
        NSLog("function006")
    }

編集時のバージョン

10.11