Signal-iOS/SignalServiceKit/src/Util/Decimal+Rounded.swift
Evan Hahn 20a2cf7311 Use title casing in filenames
This change should have no user impact.

`Error+isRetryable.swift` is now `Error+IsRetryable.swift`, and others
like it.

To find the files, I ran this:

    git ls-files | grep -E '\+[a-z]'
2022-11-10 19:08:44 -08:00

29 lines
863 B
Swift

//
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
public extension Decimal {
/// Round a decimal value to the nearest whole number.
///
/// Uses ["plain" rounding][0] to break ties.
///
/// - Returns: The decimal value roudned to the nearest whole number.
///
/// [0]: https://developer.apple.com/documentation/foundation/nsdecimalnumber/roundingmode/plain
func rounded() -> Decimal {
let nsSelf = self as NSDecimalNumber
let nsResult = nsSelf.rounding(accordingToBehavior: NSDecimalNumberHandler(
roundingMode: .plain,
scale: 0,
raiseOnExactness: false,
raiseOnOverflow: false,
raiseOnUnderflow: false,
raiseOnDivideByZero: false
))
return nsResult as Decimal
}
}