Results 1 to 2 of 2

Thread: Percentages

  1. #1
    Join Date
    Jun 2007
    Location
    Manchester
    Posts
    5

    Percentages

    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

  2. #2
    Join Date
    Dec 2004
    Posts
    2,788
    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.

Similar Threads

  1. processing 2 dictionaries at same time to calculate percentages.
    By numbenator in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 17 Aug 2005, 05:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •