Skip to content

Commit 764c2f2

Browse files
committed
NumericTextStyle/interpret(_:) format style is now rounded(.towardZero).
1 parent 46cb220 commit 764c2f2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Sources/NumericTextStyles/Format.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Foundation
3535
public protocol NumericTextFormat: ParseableFormatStyle where FormatInput: NumericTextValue, FormatOutput == String {
3636
associatedtype NumericTextScheme: NumericTextStyles.NumericTextScheme
3737
associatedtype SignDisplayStrategy: NumericTextSignDisplayStrategyRepresentable
38+
associatedtype RoundingIncrement
3839

3940
//=------------------------------------------------------------------------=
4041
// MARK: State
@@ -49,6 +50,7 @@ public protocol NumericTextFormat: ParseableFormatStyle where FormatInput: Numer
4950
@inlinable func sign(strategy: Self.SignDisplayStrategy) -> Self
5051
@inlinable func precision(_ precision: NumberFormatStyleConfiguration.Precision) -> Self
5152
@inlinable func decimalSeparator(strategy: NumberFormatStyleConfiguration.DecimalSeparatorDisplayStrategy) -> Self
53+
@inlinable func rounded(rule: FloatingPointRoundingRule, increment: Self.RoundingIncrement?) -> Self
5254

5355
//=------------------------------------------------------------------------=
5456
// MARK: Translation
@@ -66,6 +68,7 @@ extension NumericTextFormat {
6668
@usableFromInline typealias Precision = NumberFormatStyleConfiguration.Precision
6769
@usableFromInline typealias Separator = NumberFormatStyleConfiguration.DecimalSeparatorDisplayStrategy
6870
@usableFromInline typealias Sign = NumericTextSignDisplayStrategy
71+
@usableFromInline typealias Rounded = FloatingPointRoundingRule
6972

7073
//=------------------------------------------------------------------------=
7174
// MARK: Parse
@@ -86,6 +89,10 @@ extension NumericTextFormat {
8689
@inlinable func separator(_ strategy: Self.Separator) -> Self {
8790
self.decimalSeparator(strategy: strategy)
8891
}
92+
93+
@inlinable func rounded(_ strategy: Self.Rounded) -> Self {
94+
self.rounded(rule: strategy, increment: nil)
95+
}
8996
}
9097

9198
//*============================================================================*

Sources/NumericTextStyles/Style.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension NumericTextStyle {
100100
//=------------------------------------------------------------------------=
101101

102102
@inlinable public func interpret(_ value: Value) -> Commit<Value> {
103-
let style = format.precision(precision.active())
103+
let style = format.precision(precision.active()).rounded(.towardZero)
104104
var value = value
105105
//=--------------------------------------=
106106
// MARK: Autocorrect

0 commit comments

Comments
 (0)