<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Int/magnitude-swift.property",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Si9magnitudeSuvp"
  },
  "title" : "magnitude"
}
-->

# magnitude

The magnitude of this value.

```
var magnitude: UInt { get }
```

## Discussion

For any numeric value `x`, `x.magnitude` is the absolute value of `x`.
You can use the `magnitude` property in operations that are simpler to
implement in terms of unsigned values, such as printing the value of an
integer, which is just printing a ‘-’ character in front of an absolute
value.

```
let x = -200
// x.magnitude == 200
```

The global `abs(_:)` function provides more familiar syntax when you need
to find an absolute value. In addition, because `abs(_:)` always returns
a value of the same type, even in a generic context, using the function
instead of the `magnitude` property is encouraged.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)