Openfoodnetwork: Volume quantity 350mL gets transformed to 349.999999 on some products

Created on 25 May 2018  路  3Comments  路  Source: openfoodfoundation/openfoodnetwork

Description

A producer sells a beverage that is 350mL volume. He enters 350 in "value" and select mL as unit, but the value gets transformed to 349.999999.

Expected Behavior

It remains what is entered (350 here)

Actual Behavior

It doesn't

Steps to Reproduce

  1. Create a new product, select mL as unit and enter 350.
  2. See in bulk edit view.

Animated Gif/Screenshot

https://www.useloom.com/share/1775169424c844438e880ec5c32a28c2

Context

Reported by a producer on French instance.

Severity

S3, there is a workaround using the dispay as field.

Your Environment

  • Version used: v1.12
  • Browser name and version: Chrome Version 64.0.3282.167 (Official Build) (64-bit)
  • Operating System and version (desktop or mobile): Ubuntu 16.04 LTS
bug-s3

All 3 comments

A classic Javascript problem. Javascript math is broken, because in javascript 0.1 + 0.2 != 0.3
I put a simple quickfix to the problem. I think it's ok for what it is. Other more robust solutions to the problem are possible (for example, using third party lib for js math).

I didn't know about JS math but it's something to keep in mind of more issues like this come up

I've noticed the same issue on the UK OFN platform. We are selling milk in 1 pint bottles which we are recording as 568ml. However, this is displayed as 567.99999 mL.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RachL picture RachL  路  3Comments

filipefurtad0 picture filipefurtad0  路  3Comments

HugsDaniel picture HugsDaniel  路  3Comments

andrewpbrett picture andrewpbrett  路  3Comments

filipefurtad0 picture filipefurtad0  路  3Comments