Whing Dela Cruz
asked on
toFixed not working
Hi experts, I'm having problem getting toFixed (Javascript). Please correct my code below. Thanks!
var x = (this.responseText);
alert(x.toFixed(0));
alert(x.toFixed(2));
ASKER
Hi Scott, I tried "var x = (13);" and its working. I'm having error when using (this.responseText). An error says; "x.toFixed(2 is not s function"
Did you find out what this.responseText is outputting?
ASKER
The (this.responseText) is 499,212 I got that result when using alert(this.responseText) alone.
ASKER
Hi Scott, I attached here the codes which have a perfect scenario of my problem above. Hope you can extend your help.
<!DOCTYPE html>
<html>
<body>
<input type="text" id="a1"/><br/><br/>
<input type="text" id="a2"/><br/><br/>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var str = document.getElementById('a1').value;
document.getElementById('a2').value = (str.toFixed(2));
}
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much Scott, Its working. More power to you, and God bless!
Try
Open in new window
You are not providing the actual error you are getting. My guess it has to do with
Open in new window
Try outputting your response.Text to see if it looks like what you expect.