Questions tagged [bignumber.js]

31 questions
6
votes
1 answer

What is the meaning of `c`, `e`, and `s` in bignumber.js?

What are the meanings of the c, e, and s fields in the object produced by bignumber.js? For example: > new BigNumber('1234') { c: [1234], e: 3, s: 1 } > new BigNumber('12345678901234567890') { c: [123456, 78901234567890], e: 19, s: 1 }
David Wolever
  • 148,955
  • 89
  • 346
  • 502
2
votes
1 answer

How to divide numbers in JavaScript to arbitrary precision (e.g. 28 decimal places)

I'm aware of https://floating-point-gui.de/ and the fact that there are many libraries available to help with big numbers, but I've surprisingly been unable to find anything that handles more than 19 decimal places in the result of a division…
Ryan
  • 22,332
  • 31
  • 176
  • 357
1
vote
0 answers

How to format BigNumbers.js to min and max decimals

I would like to specify min and max decimal places for the toFormat method in bignumber.js. https://github.com/MikeMcl/bignumber.js/ Consider the following code: format = { prefix : '', decimalSeparator : ',', …
piece
  • 63
  • 8
1
vote
1 answer

bignumber.js modulo negative returns incorrect value

The following code should return 16. However, it returns -1. import BigNumber from 'bignumber.js'; const a = BigNumber(-1) const p = BigNumber(17) console.log(a.modulo(p)) The documentation does not provide clarity on how to handle this situation.
Soubriquet
  • 3,100
  • 10
  • 37
  • 52
1
vote
1 answer

Cannot compute large numbers with great precision in JavaScript

Im working on a cryptography solution which would implement Shamirs Secret Sharing, here I am generating a secret key based on the password provided by the user. These password when converted to number yield very large numbers and I would like to…
1
vote
0 answers

testing solidity - Error: invalid BigNumber value, when passing object as argument

I have a function in my Solidity which takes a struct as first parameter: function mintGenesisAnimal(AnimalInfo memory _animalInfo, string memory _tokenUri) onlyOwner public { // ... } but when I'm trying to test this function with the code…
Alxndr BRL
  • 371
  • 1
  • 2
  • 9
1
vote
1 answer

Handling rounding issue with BigNumber

I am trying to subtract two numbers with more decimals. But it is rounding up. How can I use BigNumber to make sure the numbers are not rounded and the calculation is precise. const myObj = { total: 5000000, filled:…
Kiran Dash
  • 4,816
  • 12
  • 53
  • 84
1
vote
1 answer

What's the point of converting to BN twice?

Debugging a smart contract test, I'm seeing the following operation: const alice_Before = toBN(web3.utils.toBN(await web3.eth.getBalance(alice))); where toBN is static toBN(num) { return web3.utils.toBN(num) } if I console.log the two…
Vlad
  • 465
  • 7
  • 26
1
vote
1 answer

Converting BigNumber to Int like in Kotlin

I have the following in Kotlin to convert a BigInteger down to ordinary integer val bigIntDiv = bigIntVal?.div(BigInteger.valueOf(429496)) val resultInt = bigIntDiv?.toInt() //This line converts the big Interger down to regular integer How…
mekings
  • 361
  • 3
  • 17
1
vote
1 answer

BigNumber.js calculation shows different value when done same calculation in C# using decimal datatype

I have been using BigNumber.js library for high precision arithmetic calculation. To maintain higher precision I am using toFixed method of the Bignumber object like this: (new BigNumber(6000 )).minus(9006000).div(9006000).times(4503000…
nraina
  • 324
  • 2
  • 20
1
vote
2 answers

Is there a way to get more precise result when dividing Big Number?

I need to operate on Big Numbers but I need the results to be precise, like below: const BN = require('bn.js'); var a = 11060622312717714974 var b = 1570481433500000000000; console.log(a/b); //0.0070428227146040415 When I use Big Number I get only…
j809809jkdljfja
  • 767
  • 2
  • 9
  • 25
1
vote
1 answer

Trying to handle big numbers with bignumber.js

My issue is that I have to do calculations with big numbers (large decimals) in javascript, such as: 1.1e-40 + 1.1e-40 Javascript only supports up to 16 digits of accuracy. So I revert to the library of MikeMcl bignumber.js As explained in the…
WJA
  • 6,676
  • 16
  • 85
  • 152
0
votes
1 answer

How to declare an item as a BigNumber with TypeScript & zod

I'm parsing input in TypeScript using zod, and attempting to replace the following interface with a zod type: interface args { quantity: number; hugeNum: BigNumber; } Declaring this with zod, I get: const numConstraints =…
pikovayadama
  • 808
  • 2
  • 8
  • 26
0
votes
0 answers

Ethers.js integrated BigNumbers & FixedNumbers resolves gt 0 numbers as 0x00

I'm using the below method to discover reserves and derive price on univ2 clones using BigNumbers & FixedNumbers implementation in Ethers, but BigNumbers is returning 0x00 even though prices are above positive integers. I have also tried using…
0
votes
1 answer

Ethers BigNumber to USD conversion

I'm trying to convert an Ethereum value to its retrospective fiat value. The final value of USD seems wrong, and I wonder if it's how it's calculated with big numbers. I've attached a sandbox for…
Xavier
  • 93
  • 1
  • 4
1
2 3