$pdata['PAYED_TOTAL'] = (int) $data['total'];

Discussion in 'PHP' started by Brilliances, Oct 23, 2006.

  1. #1
    The (int) in

    $pdata['PAYED_TOTAL'] = (int) $data['total'];

    is making my amounts round down to the nearest integer. Should this be (float) or (double)?

    The column is defined as decimal(8,2)
     
    Brilliances, Oct 23, 2006 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Your $pdata['PAYED_TOTAL'] will not be decimal or float because you use (int) so your value will be negative or positive integer.
     
    php-lover, Oct 23, 2006 IP
  3. Brilliances

    Brilliances Active Member

    Messages:
    619
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I meant I didn't want it to be rounding (up or down). I just want it to have the correct dollar value.

    This is code that is in phpLD 2.0 and I've debugged it down to this line of code. I'm just wondering if I should use (float) or (double) or something else instead of (int) to make it work.
     
    Brilliances, Oct 23, 2006 IP
  4. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Chemo, Oct 23, 2006 IP
  5. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #5
    number_format() still round the value like number_format(210.73) will be 211


    try write your own function like this example

    $num = 210.73;
    function no_round($value){
    $val = explode('.',$value);
    echo $val[0];
    }


    no_round($num);
     
    php-lover, Oct 23, 2006 IP
  6. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OK...I assumed a link to the page would give a hint on how to use the function. It will not round the number...it will format a float number.
    
    $pdata['PAYED_TOTAL'] = number_format($data['total'], 2, '.', ',');
    echo $pdata['PAYED_TOTAL'];
    // outputs xxx.yy (formatted to 2 decimal places)
    
    PHP:
    Bobby
     
    Chemo, Oct 23, 2006 IP
  7. Brilliances

    Brilliances Active Member

    Messages:
    619
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    60
    #7
    thanks.

    I believe this will do the trick

    $pdata['PAYED_TOTAL'] = round($data['total'],2);

    Too bad i can't do an e2e test on this because it's only executed after the paypal successful payment page.

    Is there a setting to switch paypal to testing mode?
     
    Brilliances, Oct 23, 2006 IP