-1

I have HTML code:

<input type="number" max>

So, when I paste bigint into this input and try to increment or decrement, input value becomes in scientific notation format. I need to remove scientific notation format and get incremented or decremented value of this bigint number using JavaScript.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Azizxon Zufarov
  • 107
  • 1
  • 3
  • 8

1 Answers1

1

Internally I've a feeling an input type number is going to be using the Number type, and not the bigint. You will likely need to just use a normal string input, and handle the increment, decrement manually..

Below is an example, you will probably want to extend to handle keypress for number etc, you could alter the look and feel to make it appear like a number input etc.

const [iBig, iNorm] = document.querySelectorAll('input');

iNorm.value = 10000000000000000000000;

const [btnUp, btnDown] = [...document.querySelectorAll('button')];

btnUp.addEventListener('click', () => {
  iBig.value = (BigInt(iBig.value) + 1n).toString();
});
btnDown.addEventListener('click', () => {
  iBig.value = (BigInt(iBig.value) - 1n).toString();
});
<p>Handle our bigint's manually.</p>
<input
value="10000000000000000000000" style="width: 200px"/>
<button>⬆</button>
<button>⬇</button>


<br/>
<p>Normal input.. with such a big number does not work</p>
<input
value="" style="width: 200px" type="number"/>
Keith
  • 22,005
  • 2
  • 27
  • 44
  • I am doing it in jquery but it does not work. I mean BigInt() method``` $('.plus').click(function(event) { event.preventDefault(); let number = $(event.target.parentElement).find('.number--field'); let count = (BigInt(number.val()) + 1n).toString; console.log(count); });``` – Azizxon Zufarov Oct 10 '22 at 16:20
  • @AzizxonZufarov jQuery will make no difference, might be an idea to knock up a snippet showing the problem. – Keith Oct 11 '22 at 10:27