<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FormatStyle/measurement(width:usage:numberFormatStyle:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11FormatStylePAAE11measurement5width5usage06numberbC0AA11MeasurementVAASo11NSDimensionCRbzrlEABVyqd___GAL9UnitWidthVyqd____G_AA0hbJ5UsageVyqd__GAA013FloatingPointbC0VySdGSgtAMRszAKRbd__lFZ"
  },
  "title" : "measurement(width:usage:numberFormatStyle:)"
}
-->

# measurement(width:usage:numberFormatStyle:)

Returns a format style to format measurement units.

```
static func measurement<UnitType>(width: Measurement<UnitType>.FormatStyle.UnitWidth, usage: MeasurementFormatUnitUsage<UnitType> = .general, numberFormatStyle: FloatingPointFormatStyle<Double>? = nil) -> Self where Self == Measurement<UnitType>.FormatStyle, UnitType : Dimension
```

## Parameters

`width`

The width — such as full names or abbreviations — with which to present units.

`usage`

The contextual usage of the measurement unit, such as whether a length measurement applies to a road distance or a person’s height.

`numberFormatStyle`

The format style with which to format the numeric part of the measurement.

## Return Value

A format style that formats measurements according to the given parameters.

## Discussion

Use the dot-notation form of this type method when the call point allows the use of [`Measurement.FormatStyle`](/documentation/Foundation/Measurement/FormatStyle). You typically do this when calling the [`formatted(_:)`](/documentation/Foundation/Measurement/formatted(_:)) method of [`Measurement`](/documentation/Foundation/Measurement).

The following example creates an array of [`Measurement`](/documentation/Foundation/Measurement) values that represent distances measured in kilometers. It then uses [`formatted(_:)`](/documentation/Foundation/Measurement/formatted(_:)) and the format style provided by this method to format the distances. The style specifies the [`asProvided`](/documentation/Foundation/MeasurementFormatUnitUsage/asProvided) usage to keep the formatted measurements in kilometers. Without this, a non-Metric locale such as the US would convert the kilometers to a locale-appropriate unit, such as miles.

```swift
let rawDistances: [Double] = [100, 1000, 10000, 100000, 1000000]
let distances = rawDistances.map { Measurement(value: $0, unit: UnitLength.kilometers) }
let formattedDistances = distances.map { $0.formatted(
    .measurement(width: .narrow,
                 usage: .asProvided,
                 numberFormatStyle: .number)) } // ["100km", "1,000km", "10,000km", "100,000km", "1,000,000km"]
```

---

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)