Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Adding 2 func to core/util.js #2197

Closed
hiyan opened this issue May 21, 2018 · 3 comments
Closed

Adding 2 func to core/util.js #2197

hiyan opened this issue May 21, 2018 · 3 comments

Comments

@hiyan
Copy link
Contributor

hiyan commented May 21, 2018

Hi @askmike, would you mind if I add these 2 function to core/util.js?

  • round for rounding off the fractions issue (Eg: 0.145 * 100 = 14.499999999999998)

  • getPrecision will return the number of decimal count

  round: function(value, decimals = 14) {
    return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
  },

  getPrecision: function(n) {
    if (!isFinite(n)) return 0;
    var e = 1, p = 0;
    while (Math.round(n * e) / e !== n) { e *= 10; p++; }
    return p;
  },
@askmike
Copy link
Owner

askmike commented May 22, 2018

Hey! This is indeed very handy, but it's almost always used in a context of dealing with exchanges. In that case it would make more sense to make it available through Gekko Broker (see #2118). On top of that: Gekko makes a lot of use of the library Lodash, the version of Lodash used by Gekko is very old, but I want to update it so we can use Lodash' round method, see here: https://lodash.com/docs/4.17.10#round

What do you think?

@hiyan
Copy link
Contributor Author

hiyan commented May 23, 2018

Yeap, mainly using it for output and fixing issues with the exchange returning errors.
Having lodash do it would be better. Since you're upgrading, i guess this is not needed.

@askmike
Copy link
Owner

askmike commented May 23, 2018

cool!

@askmike askmike closed this as completed May 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants