Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed decimalSeparator for locale with "," symbol #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/NPBaseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ open class NPBaseConfig<T>: ObservableObject

// MARK: - Public Properties

public var decimalCharacter: Character { Locale.current.decimalSeparator?.first ?? "." }

public var showDecimalPoint: Bool { false }

public var stringValue: String {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NPDecimalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class NPDecimalConfig: NPBaseConfig<Decimal> {

override public func decimalPointAction() -> Bool {
guard decimalPointIndex == nil else { return false }
sValue.append(".")
sValue.append(decimalCharacter)

return true
}
Expand Down Expand Up @@ -82,6 +82,6 @@ public final class NPDecimalConfig: NPBaseConfig<Decimal> {
}

internal var decimalPointIndex: String.Index? {
sValue.firstIndex(of: ".")
sValue.firstIndex(of: decimalCharacter)
}
}
4 changes: 2 additions & 2 deletions Sources/NPFloatConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class NPFloatConfig<T>: NPBaseConfig<T>

override public func decimalPointAction() -> Bool {
guard decimalPointIndex == nil else { return false }
sValue.append(".")
sValue.append(decimalCharacter)

return true
}
Expand Down Expand Up @@ -85,6 +85,6 @@ public final class NPFloatConfig<T>: NPBaseConfig<T>
}

internal var decimalPointIndex: String.Index? {
sValue.firstIndex(of: ".")
sValue.firstIndex(of: decimalCharacter)
}
}
2 changes: 1 addition & 1 deletion Sources/NumberPad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct NumberPad<T>: View

private var decimalPoint: some View {
Button(action: decimalPointAction) {
Text(".")
Text(String(config.decimalCharacter))
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Expand Down