---
title: "unitString(fromJoules:usedUnit:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/energyformatter/unitstring(fromjoules:usedunit:)"
---

# unitString(fromJoules:usedUnit:)

Returns the unit string for the provided value.

## Declaration

```swift
func unitString(fromJoules numberInJoules: Double, usedUnit unitp: UnsafeMutablePointer<EnergyFormatter.Unit>?) -> String
```

## Parameters

- `numberInJoules`: The energy value in joules.
- `unitp`: An output parameter. This will hold the doc://com.apple.foundation/documentation/Foundation/EnergyFormatter/Unit value that corresponds to the returned units.

## Return Value

Return Value A localized string representing the unit.

## Discussion

Discussion This method selects the correct unit based on the formatter’s locale, the magnitude of the value, and the isForFoodEnergyUse property.

## 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(fromValue:unit:)](foundation/energyformatter/unitstring(fromvalue:unit:).md)
- [unitStyle](foundation/energyformatter/unitstyle.md)
