pint icon indicating copy to clipboard operation
pint copied to clipboard

format_babel doesn't use comma seperator from babel locale

Open lassebomh opened this issue 1 year ago • 2 comments

I am trying to use pint to convert units and format them using format_babel, but numeric formats doesn't seem to respect the given locale.

Versions:

babel = "2.12.1"
pint = "0.22"

Example:

from babel import Locale
from pint import UnitRegistry

loc = Locale('da_DK')

ureg = UnitRegistry()
Q_ = ureg.Quantity

Q_('2 * feet').to('meter').format_babel(locale=loc)
> '0.6095999999999999 meter'

In Denmark we use comma as a decimal seperator, but here it's dot seperated. Am I missing something?

lassebomh avatar Sep 21 '23 14:09 lassebomh

Indeed, there seems to be a bug her. Will fix in the next version.

hgrecco avatar Oct 15 '23 18:10 hgrecco

Pint only supports babel <2.8 for now https://github.com/hgrecco/pint/blob/fc1aeba21823092007adc62fae96596e15aa0127/pyproject.toml#L62C1-L62C6

If I remeber correctly pint depended on some private part of babel that broke with babel>2.8.

if anyone is interested in looking into that.

jules-ch avatar Nov 29 '23 22:11 jules-ch