From ee9b7a0f3bae8387f3e6ffc41b9b8983e8b68690 Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Mon, 20 Nov 2023 16:30:40 -0800 Subject: [PATCH] `Double` and `CGFloat`: Added `integralDigitPlaces` and `fractionDigitPlaces` properties --- .../Extensions/CoreGraphics/CGFloat.swift | 23 +++++++++++++++++++ .../FloatingPoint and Foundation.swift | 18 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Sources/OTCore/Extensions/CoreGraphics/CGFloat.swift b/Sources/OTCore/Extensions/CoreGraphics/CGFloat.swift index 1773924..0a46628 100644 --- a/Sources/OTCore/Extensions/CoreGraphics/CGFloat.swift +++ b/Sources/OTCore/Extensions/CoreGraphics/CGFloat.swift @@ -69,4 +69,27 @@ extension StringProtocol { } } +#if canImport(Foundation) +import Foundation + +// MARK: - Digit Places + +extension CGFloat { + /// **OTCore:** + /// Returns the number of digit places of the ``integral`` portion (left of the decimal). + @inlinable @_disfavoredOverload + public var integralDigitPlaces: Int { + Decimal(self).integralDigitPlaces + } + + /// **OTCore:** + /// Returns the number of digit places of the ``fraction`` portion (right of the decimal). + @inlinable @_disfavoredOverload + public var fractionDigitPlaces: Int { + Decimal(self).fractionDigitPlaces + } +} + +#endif + #endif diff --git a/Sources/OTCore/Extensions/Foundation/FloatingPoint and Foundation.swift b/Sources/OTCore/Extensions/Foundation/FloatingPoint and Foundation.swift index e360e04..d43feab 100644 --- a/Sources/OTCore/Extensions/Foundation/FloatingPoint and Foundation.swift +++ b/Sources/OTCore/Extensions/Foundation/FloatingPoint and Foundation.swift @@ -68,4 +68,22 @@ extension FloatingPoint where Self: CVarArg, } } +// MARK: - Digit Places + +extension Double { + /// **OTCore:** + /// Returns the number of digit places of the ``integral`` portion (left of the decimal). + @inlinable @_disfavoredOverload + public var integralDigitPlaces: Int { + Decimal(self).integralDigitPlaces + } + + /// **OTCore:** + /// Returns the number of digit places of the ``fraction`` portion (right of the decimal). + @inlinable @_disfavoredOverload + public var fractionDigitPlaces: Int { + Decimal(self).fractionDigitPlaces + } +} + #endif