faqts : Computers : Programming : Languages : JavaScript : Language Core : Numbers

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 14 people (57%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I format a number to percentage format (e.g. 40.00%)?

Mar 22nd, 2000 16:21
Martin Honnen,


Use the round function of
http://www.faqts.com/knowledge-base/view.phtml/aid/1157/fid/209/lang/
plus the following function

function formatPercentage (n) {
  return round(n * 100) + '%';
}

Example:
  alert(formatPercentage(.4))