Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSkwiggs committed Jan 28, 2025
1 parent 91ca670 commit 8a37ee6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Ignite/Framework/NumberFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

internal struct NumberFormatter {
/// A number formatter that formats numbers with a single decimal, using the `.` separator. Locale-independent.
private static let doubleFormatter: Foundation.NumberFormatter = {
let formatter = Foundation.NumberFormatter()
formatter.numberStyle = .decimal
Expand All @@ -16,14 +17,17 @@ internal struct NumberFormatter {
return formatter
}()

/// Formats a double value as a string. Locale-independent.
static func format(_ value: Double) -> String {
doubleFormatter.string(for: value) ?? value.formatted()
}

/// Formats a percentage value as a string. Locale-independent.
static func format(_ value: Percentage) -> String {
doubleFormatter.string(for: value) ?? value.value.formatted()
}

/// Formats a float value as a string. Locale-independent
static func format(_ value: Float) -> String {
doubleFormatter.string(for: value) ?? value.formatted()
}
Expand Down

0 comments on commit 8a37ee6

Please sign in to comment.