Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q363 Is there an easy way to change a decimal number string (i.e. .5, .25) into a percentage (i.e. 50%, 25%)?

irt.org | Knowledge Base | JavaScript | Number | Q363 [ previous next ]

Q363 Is there an easy way to change a decimal number string (i.e. .5, .25) into a percentage (i.e. 50%, 25%)?

Simple. Multiply by 100 and then round:

<SCRIPT LANGAUGE="JavaScript"><!--
function percent(x) { return Math.round((x-0)*100) + '%'; }

document.write(percent(.5) + '<BR>');
document.write(percent(.25) + '<BR>');
document.write(percent('0.13333') + '<BR>');
//--></SCRIPT>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.