Skip to content

Commit c1d0971

Browse files
authored
Merge pull request #2345 from spevans/pr_numberformatter_update
Update NumberFormatter for better default values and Darwin compatibility
2 parents fe53405 + 533cb71 commit c1d0971

File tree

3 files changed

+510
-150
lines changed

3 files changed

+510
-150
lines changed

Foundation/ByteCountFormatter.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,14 @@ open class ByteCountFormatter : Formatter {
350350
let result: String
351351
//Need to add in an extra case for negative numbers as NumberFormatter formats 0.005 to 0 rather than
352352
// 0.01
353+
numberFormatter.minimumFractionDigits = 0
354+
numberFormatter.maximumFractionDigits = 2
353355
if bytes < 0 {
354356
let negBytes = round(bytes * 100) / 100
355357
result = numberFormatter.string(from: NSNumber(value: negBytes))!
356358
} else {
357-
numberFormatter.minimumFractionDigits = 0
358-
numberFormatter.maximumFractionDigits = 2
359359
result = numberFormatter.string(from: NSNumber(value: bytes))!
360360
}
361-
362-
363361
return partsToIncludeFor(value: result, unit: unit)
364362
}
365363
//zeroPadsFractionDigits is false, isAdaptive is false

0 commit comments

Comments
 (0)