Strapi: MySQL Float does not store complete accuracy of values.

Created on 8 May 2018  路  3Comments  路  Source: strapi/strapi




Informations

  • Node.js version: v9.11.1
  • npm version: 5.6.0
  • Strapi version: 3.0.0-alpha.12.1.3
  • Database: 10.2.14-MariaDB
  • Operating system: Ubuntu 16.04 LTS

What is the current behavior?

Currently the float type of MySQL doesn't properly store a long integer value of a length over a certain amount and will round up or down depending on the length which could cause problems specifically when dealing with large numbers.

Steps to reproduce the problem

create an float type and enter a value such as 36028807496337770

What is the expected behavior?

Float values stored in the API should not round.

Suggested solutions

A new data type could be created within the admin panel for the Double data type in MySQL or within Strapi-Bookshelf the following code:

                          case 'float':
                          case 'decimal':
                            type = attribute.type;
                            break;
                          case 'date':

could be changed to:

                          case 'float':
                            type = 'double';
                            break;
                          case 'decimal':
                            type = 'decimal';
                            break;
                          case 'date':

  • [x] I'm sure that this feature hasn't already been referenced.
help wanted

All 3 comments

I have tested this locally and it does work as intended, if such a change is accepted I can create a pull request.

It's okay to create a PR for this. We have a better support on MongoDB so we should do the same on SQL databases.

Will do @Aurelsicoko I'll get one created and submitted in the next few minutes :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dufoli picture dufoli  路  3Comments

monkibraum picture monkibraum  路  3Comments

mnlbox picture mnlbox  路  3Comments

wes-cutting picture wes-cutting  路  3Comments

quibaritaenperdresatrompe picture quibaritaenperdresatrompe  路  3Comments