0

I have created a custom Decimal initializer that takes another Decimal and rounds it so it has a maximum of 2 decimals:

extension Decimal {
    public init(rounding decimal: Decimal) {
        var result: Decimal = 0
        var number = decimal
        NSDecimalRound(&result, &number, 2, .plain)
        self = result
    }
} 

So far it seems to be working, enter image description here

However, I am unable to generate a unit test to recreate the expected output.

func testDecimalRoundingInitializer() {
    let input: Decimal = 1.1234
    let expectedResult: Decimal = 1.12
    XCTAssertEqual(Decimal(rounding: input), expectedResult)
}

enter image description here

Any ideas on how I can create my unit test?

Sorry if the questions seem a little bit silly...

Reimond Hill
  • 4,278
  • 40
  • 52

0 Answers0