---
title: "formatted(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/measurement/formatted(_:)"
---

# formatted(_:)

Generates a locale-aware string representation of a measurement using the provided measurement format style.

## Declaration

```swift
func formatted<S>(_ style: S) -> S.FormatOutput where S : FormatStyle, S.FormatInput == Measurement<UnitType>
```

## Parameters

- `style`: The measurement format style to apply to the measurement.

## Return Value

Return Value A string, formatted according to the provided style.

## Discussion

Discussion Use the formatted(_:) method to create a string representation of a measurement using a custom measurement format style. You can specify the width of the unit name, the numeric formatting of the value, and the intended usage type of the measurement. You can use the Measurement.FormatStyle static factory method measurement(width:usage:numberFormat:) to create a custom format style as a parameter to the method, such as in the following example: let temp = Measurement<UnitTemperature>(value: 38, unit: .celsius) let formattedTemp = temp.formatted(.measurement(width: .wide, usage: .weather, numberFormat: .numeric(precision: .fractionLength(1)))) // For locale: en_US: 100.4 degrees Fahrenheit

## See Also

### Formatting a Measurement

- [formatted()](foundation/measurement/formatted().md)
- [Measurement.FormatStyle](foundation/measurement/formatstyle.md)
- [Measurement.AttributedStyle](foundation/measurement/attributedstyle.md)
