ABEO Posted August 28, 2008 Share Posted August 28, 2008 I am working on a website and I have a mortgage calculator.I want to limit the number of decimal places in the output, is that possible?(so instead of displaying "1234.56789" it will display "1234.57")Thanks Link to comment Share on other sites More sharing options...
ABEO Posted August 29, 2008 Author Share Posted August 29, 2008 Ok adding ".toFixed(2)" works in Internet Explorer, but now firefox just doesn't display the result. Any ideas? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 29, 2008 Share Posted August 29, 2008 (edited) Ok adding ".toFixed(2)" works in Internet Explorer, but now firefox just doesn't display the result. Any ideas?Sounds like you're trying to use the toFixed method on a var containing a string (even though it contains numbers), and that will throw an error instead of work, specifically "yourvarnamehere.toFixed is not a function". So try to convert the contents of the variable you fill from the inputbox to a number first (many simple ways to do that, including Number() or subtracting 0 from it).A quick and dirty example of that (including the 2 quick & simple methods I just mentioned):<script type="text/javascript">var somestring = prompt("Enter a number","12.34567890")var test1 = Number(somestring)var test2 = somestring - 0alert ("The number is: " + test1.toFixed(2) + " or " + test2.toFixed(2))</script>If you're using Firefox, you might as well take advantage of the far superior web dev tools, like the web developer toolbar, the javascript debugger, firebug and all those. Edited August 29, 2008 by crahak Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now