---
title: "unitString(fromValue:unit:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/energyformatter/unitstring(fromvalue:unit:)"
---

# unitString(fromValue:unit:)

Returns the unit string based on the provided value and unit.

## Declaration

```swift
func unitString(fromValue value: Double, unit: EnergyFormatter.Unit) -> String
```

## Parameters

- `value`: The energy value in the provided unit.
- `unit`: The unit to use in the resulting energy string.

## Return Value

Return Value A localized string representing the given unit. The provided value determines whether the unit is plural or singular.

## See Also

### Formatting Energy Strings

- [isForFoodEnergyUse](foundation/energyformatter/isforfoodenergyuse.md)
- [getObjectValue(_:for:errorDescription:)](foundation/energyformatter/getobjectvalue(_:for:errordescription:).md)
- [numberFormatter](foundation/energyformatter/numberformatter.md)
- [string(fromJoules:)](foundation/energyformatter/string(fromjoules:).md)
- [string(fromValue:unit:)](foundation/energyformatter/string(fromvalue:unit:).md)
- [unitString(fromJoules:usedUnit:)](foundation/energyformatter/unitstring(fromjoules:usedunit:).md)
- [unitStyle](foundation/energyformatter/unitstyle.md)
