Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Wrong conversion from grams to kilograms in hops input #65
I've been using the .deb downloaded version so far, but today I tried the repository version. This bug happens on both branches (master and stable/2.2.0).
When trying to input an amount that has 1g precision in the hop amount field, Brewtarget automatically converts the input value to kilograms.
Multiples of 10 (10, 20, 30...) are accepted, anything else is converted to kilograms (1, 5, 7, 9, 15, 44, etc).
"5", "5g", "5 g", all of them get converted to 5 kg.
When I type "10", it gets converted to 10 kg. But "10g" and "10 g" are correctly accepted.
I'm talking about the Hops tab, where I assume should consider grams automatically, as a kilogram hop use is unlikely for homebrewers.
I tried debugging the situation and realized that the value in the database is correct.
In https://github.com/Brewtarget/brewtarget/blob/master/src/hop.cpp#L299, get("amount") returns "0.005" kilograms, correctly.
Brewtarget::toDouble() converts it to "5", because it uses QLocale.toDouble(): https://github.com/Brewtarget/brewtarget/blob/master/src/brewtarget.cpp#L1069 and I'm using "pt_BR.UTF-8", which uses period as thousands separator and comma as decimal separator.
I commented out the QLocale.toDouble(), going straight to text.toDouble(), and the values are correctly shown.
This problem isn't reproducible with LC_ALL=en_US.UTF-8.
Even when the problem doesn't happen (using en_US, for instance), I need to type "5g" for 5 grams, otherwise Brewtarget sets the amount to 5 kg. As a suggestion, I don't think one would use kg for hops amount for any batch <1000L, so it shouldn't be the default input.
Code to force the problem
Enter "3 g" into the field.
Option 1: en_US
text: "0.003" success: true ret: 0.003
Option 2: pt_BR
text: "0.003" success: true ret: 3
Each time, the string "0.003" is being passed into toDouble() as an unlocalized string. Need to find where this string originates and either localize it there, or use QString::toDouble() in this situation.
Found the problem, and it's a big one, so thank you very much Renato!
This is just supposed to return a simple
This needs to be done for all the double properties of all the ingredient classes.
added a commit
Aug 15, 2015
added a commit
Aug 15, 2015
@rocketman768 It does, thank you very much.
The only thing still subject to improvement in amounts input, IMHO, is the "default by type". I mean, the defaults are Kg and L, which works for fermentables or overall batch volumes, but not for hops (which are probably in grams), miscellaneous or yeasts. Of course needing to type the unit is not a big deal, but it is something to think of for future improvements.