Computing.Net > Forums > Web Development > format percentage

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

format percentage

Reply to Message Icon

Name: darkhalf
Date: October 28, 2005 at 06:02:02 Pacific
Comment:

Hi,

Through my math function, I'm getting a percentage.. but how do you format it? I'm getting 1.5151515151515151% when I would like to have 1%...

var percent = done/total*100;
document.getElementById('Percent').innerHTML = percent + "%";



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: October 28, 2005 at 10:58:39 Pacific
Reply:

var percent = Math.round(done/total*100);
document.getElementById('Percent').innerHTML = percent + "%";

However, 1.515151 would round up to 2! If you do not want it rounded, but instead just want the whole number minus the remainder use Math.floor(done/total*100)

Michael J


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: format percentage

Best format for streaming video? www.computing.net/answers/webdevel/best-format-for-streaming-video/413.html

Forms in HTML without mailto: www.computing.net/answers/webdevel/forms-in-html-without-mailto/518.html

XL formats of MySQL/PHP export CSV www.computing.net/answers/webdevel/xl-formats-of-mysqlphp-export-csv/1117.html