Help - Search - Members - Calendar
Full Version: [HTML] Decimal places in Input Text Box
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
ABEO
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
ABEO
Ok adding ".toFixed(2)" works in Internet Explorer, but now firefox just doesn't display the result. Any ideas?
crahak
QUOTE (ABEO @ Aug 28 2008, 08:15 PM) *
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):
CODE
<script type="text/javascript">
var somestring = prompt("Enter a number","12.34567890")
var test1 = Number(somestring)
var test2 = somestring - 0
alert ("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.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.