Custom card: Formatting numbers using User Number format preferences

I am creating a custom card which includes calculations on some numeric entity values.

If I was formatting an Entity directly on the frontend, I would use the hass.format* methods (e.g hass.formatEntityState), to format using the users Number formatting preferences. (see Entity state formatting)

But there does not appear to be a method to just format any number using the users Number formatting preferences.

Does anyone know how to do this?

I found the solution. Adding here for completion.

With the Custom Card Helper package,

import {
  formatNumber,
} from "custom-card-helpers";

and using the hass object passed into custom card, format your number like this:

formatNumber(this._your_number, this._hass.locale)