Skip to content

Commit

Permalink
fix: Correct handling of fractions without leading zero in Salt/Sodiu…
Browse files Browse the repository at this point in the history
…m content field Fixes openfoodfacts#6717
  • Loading branch information
danwyk committed Nov 18, 2023
1 parent 0c9912d commit 43748be
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion html/js/product-multilingual.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,12 +1065,19 @@ $(function() {
var source = from.val().replace(",", ".");
var regex = /^(.*?)([\d]+(?:\.[\d]+)?)(.*?)$/g;
var match = regex.exec(source);

if (match) {
var target = match[1] + (parseFloat(match[2]) * multiplier) + match[3];
var number = match[2]
if (match[1] == ".") {
number = "0." + match[2];
}

var target = match[1] + (parseFloat(number[2]) * multiplier) + match[3];
to.val(target);
} else {
to.val(from.val());
}
console.log("我们的to.val", to.val());
}

$("#nutriment_sodium_unit").change(function() {
Expand Down

0 comments on commit 43748be

Please sign in to comment.