Jump to content

formatting a number for dollars in javascript


DickDeeds

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...