Re: Using big numbers in an Extension



On Thu, Jan 7, 2016 at 4:45 AM, Florian Müllner <fmuellner gnome org> wrote:
I'm not familiar with bignumber.js, so it may just not be compatible with spidermonkey or require a version newer than the one used by gjs, however:

​Turns out I made a small mistake. This worked:

const ExtensionUtils = imports.misc.extensionUtils;
const Extension = ExtensionUtils.getCurrentExtension();
const BigNumber = Extension.imports.bignumber;

// Then, I can do:​
var number = new BigNumber.BigNumber(my_num);
var ConversionFactor = new BigNumber.BigNumber(10).pow(24);
number.dividedBy(ConversionFactor).round(2);

// etc etc

 
On Tue, Jan 5, 2016 at 8:50 PM Per <pmknutsen gmail com> wrote:
If not, how do I use a library like bignumber.js in my extension?

I have tried this:

/* Include the library */
const ExtensionUtils = imports.misc.extensionUtils;
const Extension      = ExtensionUtils.getCurrentExtension();
const BigNumber    = Extension.imports.bignumbers;

This should be Extension.imports.bignumber



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]