2017-02-23 37 views
-2

我有2個輸入框在我的html文件中設計兩個數字,如果輸出(結果)等於0.000039如何使它4×10 ^( - 5) (不是4e-4)?0.000039輸出到4×10 ^( - 5)

+0

請發表你有JavaScript代碼。 –

+0

你應該考慮添加更多的信息,也許還有一些代碼。你嘗試過什麼嗎? – Nicolas

回答

1

const output = '4e-4'; 
 
const parts = output.split('e-'); 
 
const result = `${parts[0]}x10^(-${parseInt(parts[1])+1})`; 
 
console.log(result)

0

這是我的代碼:

<!DOCTYPE html> 
<html> 
<body> 

    <input id="nb1" type="tel"> 
    <p></p> 
    <input id="nb2" type="tel"> 
    <p></p> 
    <input id="clickMe" type="button" value="=" onclick="myFun();"/> 
    <p></p> 
    <p id="result"></p> 

    <script> 

function myFun() { 

var nb1 = document.getElementById("nb1").value; 
var nb2 = document.getElementById("nb2").value; 
var x = nb1/nb2; 

document.getElementById("result").innerHTML= x; 
} 
    </script> 
</body> 
</html>