Shopify / measured

Encapsulate measurements and their units in Ruby and Ruby on Rails.
MIT License
337 stars 28 forks source link

Unexpected formatting of formatted output for converted weight #138

Open donaldpiret opened 3 years ago

donaldpiret commented 3 years ago

Hello, I'm running into a bit of an unexpected behaviour with the following code:

weight = Measured::Weight.new(value, 'kg')
weight = weight.convert_to('lbs') if current_user&.prefers_imperial?
return weight.format('%.2<value>f %<unit>s')

Now I'd expect to just see this either in KG or LBS based on the user's preferences, but instead when the weight is converted, format gives me the full conversion string for the unit, eg. 319.67 lb (45359237/100000000 kg) How do I get around this?