Math Formula issue

Math Formula issue

hubonehubone Posts: 13Questions: 4Answers: 0
    Field::inst( 'profit' )->getFormatter( function ( $val, $data, $opts ) {
        if($data['cost'] && $data['revenue'])
            return ((int)$data['cost'] / (int)$data['revenue']) * 100;
        else return 0;
        }
    )->setFormatter( function ( $val, $data, $opts ) { 
        if($data['cost'] && $data['revenue'])
            return ((int)$data['cost'] / (int)$data['revenue']) * 100;
        else return 0;
        }
    ),  

that math is coming up bad.

I'm trying to have the field profit calculate automatically the profit.
I have a cost field that I input information and revenue field that I input information.
Problem is when its a negative number it just puts 0 there and it doesn't calculate the amount correct. can someone correct this for me?

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    There is nothing in your PHP to suggest that it would not work with signed numbers. Is the database column storing unsigned data perhaps?

    Allan

  • hubonehubone Posts: 13Questions: 4Answers: 0

    What does that mean? How can I check?

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    What I mean is, what is the data type for the column in your SQL database? You would check using whatever database admin program you use, or SHOW FIELDS (or similar) if you use the CLI.

    Allan

This discussion has been closed.