SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Me On How To Use Or Write Percentages In Php

    Hello People,
    I have problem with percantages in php. I have an array of numbers measured in centimeters or pixels as follows

    PHP Code:
    $menu = new testcode("ventical.xml"128.51813018"#FFFFFF""#FFFBDE""#181C5A""#181C5A"120""1); 
    I want 128.5, 18, 130, 18 which are in centimeters or pixels to be in percentages so that it can be changing according to according to resolutions of a computer.

    How can I achieve this??
    Your help will be highly appreciated.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well... a percentage is just a part over the whole multiplied by 100. So you could just do:
    Code:
    $percentage = ((float)$part / (float)$whole) * 100.0;
    Filling in $part and $whole with whatever you like. The float casting must be done to keep it all a float.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer


Bookmarks

Posting Permissions

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