DickDeeds Posted July 13, 2008 Share Posted July 13, 2008 Hi all,If I have a number like 300, how do I format that to show 300.00? I handle bad numbers like 300.138723 using: x=Math.round(Number(document.frm_journal_entry.debit1.value)*100)/100; document.frm_journal_entry.debit1=x;but cannot find a function like instr to look for a period.Any help would be apprecieated.TIADickDeeds Link to comment Share on other sites More sharing options...
Ingolme Posted July 13, 2008 Share Posted July 13, 2008 You can try the toFixed() function: x = 300.138723alert(x.toFixed(2)); Link to comment Share on other sites More sharing options...
jhecht Posted July 14, 2008 Share Posted July 14, 2008 or the toFloat function i believe its called. Link to comment Share on other sites More sharing options...
jeffman Posted July 14, 2008 Share Posted July 14, 2008 or the toFloat function i believe its called.In mooTools, maybe. In pure javascript, I can find no such animal. Link to comment Share on other sites More sharing options...
jhecht Posted July 14, 2008 Share Posted July 14, 2008 think it might be called parseFloat in regular javascript. Not sure if its an object property or a global function though Link to comment Share on other sites More sharing options...
jeffman Posted July 14, 2008 Share Posted July 14, 2008 Global function. Like parseInt, it takes a number in string form (like you'd get out of a text input) and turns it into a number. It truncates at the first non-number character, but doesn't truncate digits, so parseFloat ("1.33333 is my name") returns 1.33333. Link to comment Share on other sites More sharing options...
jesh Posted July 14, 2008 Share Posted July 14, 2008 Global function. Like parseInt, it takes a number in string form (like you'd get out of a text input) and turns it into a number. It truncates at the first non-number character, but doesn't truncate digits, so parseFloat ("1.33333 is my name") returns 1.33333.Also, if you had "12.500000" and you ran parseFloat on it, you'd come back with "12.5" rather than "12.50" which would be expected for US currency. I believe toFixed is the way to go. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.