SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast JohnLee's Avatar
    Join Date
    Sep 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    another math problem, setting condition

    I'm having problem setting conditions to my math calculation, let's say

    PHP Code:
    $base1 "10,000";
    $base2 "20,000"
    how should i set the condition if i have 3 values which is smaller than $base1, in between $base1 and $base2 and finally bigger than $base2?

    I tried

    PHP Code:
    if ($value $base1 $base2
    which is wrong

    is there any site which I could find examples on php math calculation?

  2. #2
    SitePoint Member
    Join Date
    Apr 2003
    Location
    germany
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($x $base1) { do sth;}
    elseif (
    $x <$base2) { do sthelse;}
    else { 
    now $x is bigger than $base2
    btw.
    if u use numbers with commas they will be taken as strings, i guess. so calculations will present strange results very likely.

    a good place to start is the php-manual at www.php.net

    cheers, jens

  3. #3
    SitePoint Enthusiast SilkySmooth's Avatar
    Join Date
    May 2003
    Location
    In the PHP Engine :-)
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Here are some examples, not sure if they will help:

    PHP Code:
    if ($value>$base1 && $value<$base2)
      {
      
    value is between 10,000 and 20,000
      
    }
    if (
    $value<$base1)
      {
      
    value is less than base1
      
    }
    if (
    $value>$base2)
      {
      
    value is greater than base2
      

    HTH

  4. #4
    SitePoint Enthusiast JohnLee's Avatar
    Join Date
    Sep 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks mates, great help

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnLee
    I'm having problem setting conditions to my math calculation, let's say

    PHP Code:
    $base1 "10,000";
    $base2 "20,000"
    One small thing: You should not use "," in your numbers. This way they are not really numbers anymore.

    Simply use:

    PHP Code:
    $base1 10000;
    $base2 20000
    You can use number_format() to format the numbers. If you use:

    PHP Code:
    echo number_format(10000.23); 
    and your servers locale settings is english, the output is:

    Code:
    10,000.23


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
  •