禁用无穷大规则的科学记数法

Scientific notation with infinity rule disabled

我一直试图用科学记数法来计算结果,但无穷大规则仍然是非法的,但我似乎无法让它发挥作用。当我使用 toExponential() 函数时,它会返回一条错误消息。请问我可以帮忙吗?这是代码:

<!DOCTYPE html>
<html>
<body>
Base:<input id="n1" rows=1 cols=3 type=number">
Exponent:<input id="n2" rows=1 cols=3 type="number">
<script>
var calc=0
function calculate() {
   calc=document.getElementById("result").innerHTML = 
   BigInt(document.getElementById("n1").value)**BigInt(document.getElementById("n2").value)
   calc.toExponential()=document.getElementById("result");
}
   </script>
   <button onclick="calculate()">Calculate</button><p>=<span id="result" style=display:none></span> 
   </p>
   <script src="decimal.js/decimal.js"></script>
   </body>
   </html>

BigInt 上不存在 toExponential。由于toExponential()存在于Number.prototype.toExponential(),需要将BingInt解析为float,然后调用toExponential().

function calculate() {
  let calc = BigInt(document.getElementById("n1").value)**BigInt(document.getElementById("n2").value);
  document.getElementById("result").innerHTML = parseFloat(calc).toExponential();
  console.log(parseFloat(calc).toExponential());
}
<!DOCTYPE html>
<html>
<body>
Base:<input id="n1" rows=1 cols=3 type=number">
Exponent:<input id="n2" rows=1 cols=3 type="number">
   <button onclick="calculate()">Calculate</button><p>=<span id="result"></span> 
   </p>
   
   </body>
   </html>