Skip to content

Commit

Permalink
Set appropriate default properties for decimal number style, and adde…
Browse files Browse the repository at this point in the history
…d tests.
  • Loading branch information
Karl Weinmeister committed Dec 11, 2016
1 parent 173e9ea commit 74e880e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Foundation/NSNumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ open class NumberFormatter : Formatter {
_usesGroupingSeparator = true
_minimumFractionDigits = 2

case .decimal:
_usesSignificantDigits = false
_usesGroupingSeparator = true
_maximumFractionDigits = 3
_minimumIntegerDigits = 1

default:
_usesSignificantDigits = true
_usesGroupingSeparator = true
Expand Down
12 changes: 10 additions & 2 deletions TestFoundation/TestNSNumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ class TestNSNumberFormatter: XCTestCase {
func test_minimumIntegerDigits() {
let numberFormatter = NumberFormatter()
numberFormatter.minimumIntegerDigits = 3
let formattedString = numberFormatter.string(from: 0)
var formattedString = numberFormatter.string(from: 0)
XCTAssertEqual(formattedString, "000")

numberFormatter.numberStyle = .decimal
formattedString = numberFormatter.string(from: 0.1)
XCTAssertEqual(formattedString, "0.1")
}

func test_maximumIntegerDigits() {
Expand Down Expand Up @@ -375,8 +379,12 @@ class TestNSNumberFormatter: XCTestCase {
let numberFormatter = NumberFormatter()
numberFormatter.usesSignificantDigits = true
numberFormatter.maximumSignificantDigits = 3
let formattedString = numberFormatter.string(from: 42.42424242)
var formattedString = numberFormatter.string(from: 42.42424242)
XCTAssertEqual(formattedString, "42.4")

numberFormatter.numberStyle = .decimal
formattedString = numberFormatter.string(from: 987654321)
XCTAssertEqual(formattedString, "987,654,321")
}

func test_stringFor() {
Expand Down

0 comments on commit 74e880e

Please sign in to comment.