PDA

View Full Version : Percentages



jonyBravo
02 Jul 2007, 04:31 AM
Hi there

My website is built in ASP and in one of my pages I've got some calculations to display the result in percentages. The problem is when it is divided by 3 or 6 or 9 etc give me a total like 33.33333333333%.
What code can I use to make only dilsplay 33.3%?

my code is as follow:

Session("team") = team * 100 / maxlist

example:

if maxlist = 3 and team = 1 session("team")= 33.33333333


Thanks in advance

alvo
04 Jul 2007, 07:16 PM
You just need to truncate the resultant number to the number of decimal places you want. This is a common need, so it crops up everywhere. In MySQL, for instance, you use the truncate() function; in PHP you use number_format. Specific code will depend on whether you want to round off the number to the shorter version or just truncate it without rounding. A Google search will give you lots of examples of how to do this. Just pick what you want to use (in this example PHP) and search for something like php truncate number.