SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I have a program which seperates values of a text variable into an array. However, when I tried to subtract the values like below...

    $oemprice_array = explode("\n",$row[oemprice]);

    $pricechange = $oemprice_array[0] - $oemprice_array[1];

    However, when $oemprice_array[0] and $oemprice_array[1] are the same, the subtraction results in -0.94999999999999.

    Could someone please tell me what is happening?
    Last edited by usbworkshop; Mar 18, 2001 at 02:50.
    Ian Chiu
    Editor in Chief
    http://www.usbworkshop.com/

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    $to_explode $row[oemprice];

    $oemprice_array explode("\n",$to_explode); 

    $oem1 $oemprice_array[0];
    $oem2 $oemprice_array[1];

    $pricechange $oem1 $oem3;

    echo(
    "$pricechange"); 
    Let me know what you get as output from that!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 1999
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your response. But I have figured out that the array should be turned into 'double' with this command in order to subtract each other correctly.

    Code:
     $retailprice_array[1] = doubleval ($retailprice_array[1]);
    Best regards,
    Ian Chiu
    Editor in Chief
    http://www.usbworkshop.com/


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
  •