Instance Property インスタンスプロパティ

usesSignificantDigits

A Boolean value indicating whether the formatter uses minimum and maximum significant digits when formatting numbers. フォーマッタが数値を書式設定している時に最小および最大有効桁数を使用するかどうかを指し示すブール値。

Declaration 宣言

@property BOOL usesSignificantDigits;

Discussion 議論

The NSNumberFormatter class has two ways of determining how many digits to represent: using integer and fraction digits and using significant digits. NSNumberFormatterクラスは、どのくらい多くの桁が表されることになるか決定する2つの方法を持ちます: 整数と小数桁を使ってそして有効桁数を使って。

When this property is set to NO, numbers are formatted according to whether you want them formatted as fractions or as integers. For more information, see Configuring Integer and Fraction Digits. This property is NO by default. このプロパティがNOに設定される場合、数値はあなたがそれを小数としてまたは整数として書式設定したいかどうかによって書式設定されます。さらなる情報として、整数および小数桁を構成設定するを見てください。このプロパティは、省略時にはNOです。

Set this property to YES to format numbers according to the significant digits configuration specified by the minimumSignificantDigits and maximumSignificantDigits properties. By default, the minimum number of significant digits is 1, and the maximum number of significant digits is 6. このプロパティをYESに設定することで、数値をminimumSignificantDigitsおよびmaximumSignificantDigitsプロパティによって指定される有効桁数構成設定によって書式設定してください。初期状態では、最小限の有効桁数は1です、そして最大限の有効桁数は6です。

The following code demonstrates the effect of configuring usesSignificantDigits when formatting various numbers: 以下のコードは、usesSignificantDigitsを様々な数値を書式設定している時に構成設定する効果を実演します:


var numberFormatter = NumberFormatter()


// Using significant digits
numberFormatter.usesSignificantDigits = true
numberFormatter.string(from: 12345678) // 12345700
numberFormatter.string(from: 1234.5678) // 1234.57
numberFormatter.string(from: 100.2345678) // 100.235
numberFormatter.string(from: 1.230000) // 1.23
numberFormatter.string(from: 0.00000123) // 0.00000123


// Using integer and fraction digits
numberFormatter.usesSignificantDigits = false
numberFormatter.string(from: 12345678) // 12345678
numberFormatter.string(from: 1234.5678) // 1235
numberFormatter.string(from: 100.2345678) // 100
numberFormatter.string(from: 1.230000) // 1
numberFormatter.string(from: 0.00000123) // 0

See Also 参照

Configuring Significant Digits 有効桁数を構成設定する