@@ -140,7 +140,7 @@ open class NumberFormatter : Formatter {
140
140
_setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterPlusSign, value: _plusSign? . _cfObject)
141
141
_setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterCurrencySymbol, value: _currencySymbol? . _cfObject)
142
142
_setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterExponentSymbol, value: _exponentSymbol? . _cfObject)
143
- _setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterMinIntegerDigits, value: _minimumIntegerDigits . _bridgeToObjectiveC ( ) . _cfObject)
143
+ _setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterMinIntegerDigits, value: minimumIntegerDigits . _bridgeToObjectiveC ( ) . _cfObject)
144
144
_setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterMaxIntegerDigits, value: _maximumIntegerDigits. _bridgeToObjectiveC ( ) . _cfObject)
145
145
_setFormatterAttribute ( formatter, attributeName: kCFNumberFormatterMinFractionDigits, value: _minimumFractionDigits. _bridgeToObjectiveC ( ) . _cfObject)
146
146
if _minimumFractionDigits <= 0 {
@@ -190,12 +190,15 @@ open class NumberFormatter : Formatter {
190
190
case . currency, . currencyPlural, . currencyISOCode, . currencyAccounting:
191
191
_usesSignificantDigits = false
192
192
_usesGroupingSeparator = true
193
+ if _minimumIntegerDigits == nil {
194
+ _minimumIntegerDigits = 1
195
+ }
193
196
_minimumFractionDigits = 2
194
197
195
198
case . decimal:
196
199
_usesGroupingSeparator = true
197
200
_maximumFractionDigits = 3
198
- if _minimumIntegerDigits == 0 {
201
+ if _minimumIntegerDigits == nil {
199
202
_minimumIntegerDigits = 1
200
203
}
201
204
if _groupingSize == 0 {
@@ -680,11 +683,14 @@ open class NumberFormatter : Formatter {
680
683
_roundingIncrement = newValue
681
684
}
682
685
}
683
-
684
- internal var _minimumIntegerDigits : Int = 0
686
+
687
+ // Use an optional for _minimumIntegerDigits to track if the value is
688
+ // set BEFORE the .numberStyle is changed. This allows preserving a setting
689
+ // of 0.
690
+ internal var _minimumIntegerDigits : Int ?
685
691
open var minimumIntegerDigits : Int {
686
692
get {
687
- return _minimumIntegerDigits
693
+ return _minimumIntegerDigits ?? 0
688
694
}
689
695
set {
690
696
_reset ( )
0 commit comments