Jump to content

formatting a number for dollars in javascript


DickDeeds
 Share

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...