나는 JavaScript를 가르치고 있고 toFixed()와 관련된 문제가있다. 저는 할부 상환 계산기를 사용하고 있습니다. 그리고 그 중 하나의 단계는 소수 자리가 많은 숫자를 반환합니다. 나는 그것을 소수점 이하 4 자리까지 줄이려고 노력하고있다. 샘플 코드에 많은 설명 HTML이 있음을 알립니다. 방정식의 단계를 통해 작업 할 수있는 것은 단지 그곳에 있습니다. 또한 매우 긴 숫자에 하나를 더하면 과학 표기법의 끝 부분에 숫자 1이 추가됩니다. MDN's documentation에서toFixed 아무 것도하지 않는다
var paymentamount;
var principal=250000;
var interestrate = 4.5;
var annualrate = interestrate/12;
var numberofpayments = 360;
document.write("This is the annuitized interest rate: "+ annualrate +"%");
document.write("<h3> Now we add 1 to the annualized interest rate</h3>");
var RplusOne = annualrate + 1;
document.write("<p> This is One Added to R: " + RplusOne + "%");
document.write("<h3>Next RplusOne is Raised to the power of N </h3>");
var RRaised = (Math.pow(RplusOne, numberofpayments)).toFixed(4);
document.write("<p>This gives us the following very long number, even thought it shouldn't: " + RRaised);
document.write("<h3>Now we add one to the very long number </h3>");
var RplusOne = RRaised + 1;
document.write("<p>Now we've added one: " + RplusOne);
'.toFixed()'함수는 숫자가 아닌 ** 문자열 **을 반환합니다. – Pointy