---
title: "formRemainder(dividingBy:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/double/formremainder(dividingby:)"
---

# formRemainder(dividingBy:)

Replaces this value with the remainder of itself divided by the given value.

## Declaration

```swift
mutating func formRemainder(dividingBy other: Double)
```

## Parameters

- `other`: The value to use when dividing this value.

## Discussion

Discussion For two finite values x and y, the remainder r of dividing x by y satisfies x == y * q + r, where q is the integer nearest to x / y. If x / y is exactly halfway between two integers, q is chosen to be even. Note that q is not x / y computed in floating-point arithmetic, and that q may not be representable in any available integer type. The following example calculates the remainder of dividing 8.625 by 0.75: var x = 8.625 print(x / 0.75) // Prints "11.5"

let q = (x / 0.75).rounded(.toNearestOrEven) // q == 12.0 x.formRemainder(dividingBy: 0.75) // x == -0.375

let x1 = 0.75 * q + x // x1 == 8.625 If this value and other are finite numbers, the remainder is in the closed range -abs(other / 2)...abs(other / 2). The formRemainder(dividingBy:) method is always exact.

## See Also

### Performing Calculations

- [Floating-Point Operators for Double](swift/floating-point-operators-for-double.md)
- [addingProduct(_:_:)](swift/double/addingproduct(_:_:).md)
- [addProduct(_:_:)](swift/double/addproduct(_:_:).md)
- [squareRoot()](swift/double/squareroot().md)
- [formSquareRoot()](swift/double/formsquareroot().md)
- [remainder(dividingBy:)](swift/double/remainder(dividingby:).md)
- [truncatingRemainder(dividingBy:)](swift/double/truncatingremainder(dividingby:).md)
- [formTruncatingRemainder(dividingBy:)](swift/double/formtruncatingremainder(dividingby:).md)
- [negate()](swift/double/negate().md)
