<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/EnergyFormatter/unitString(fromJoules:usedUnit:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSEnergyFormatter(im)unitStringFromJoules:usedUnit:"
  },
  "title" : "unitString(fromJoules:usedUnit:)"
}
-->

# unitString(fromJoules:usedUnit:)

Returns the unit string for the provided value.

```
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 [`EnergyFormatter.Unit`](/documentation/Foundation/EnergyFormatter/Unit) value that corresponds to the returned units.

## Return Value

A localized string representing the unit.

## Discussion

This method selects the correct unit based on the formatter’s locale, the magnitude of the value, and the [`isForFoodEnergyUse`](/documentation/Foundation/EnergyFormatter/isForFoodEnergyUse) property.

---

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)