denissimon / formula-parser

Parsing and evaluating mathematical formulas given as strings.
MIT License
76 stars 24 forks source link

Support for ceil #7

Closed cjaybayno closed 4 years ago

cjaybayno commented 4 years ago

Hi, I have been using your library for year now for the complex computation of our loan system and its was great. Appreciate your effort on this.

But would you mind if you can add a support to ceil the result, so I dont need to add ceil on every result

thanks,

denissimon commented 4 years ago

Hi! Thanks for using Formula Parser! Currently I have no time for adding new features, unfortunately. But I would suggest to just use an extended class, so you won't have to ceil the results every time. If I understand you correctly, the code may be something like this:

use FormulaParser\FormulaParser;
require_once __DIR__ . '/vendor/autoload.php';

class MyFormulaParser extends FormulaParser {    
    public function getResultCeil() {
        $result = $this->getResult();
        if ($result[0] == 'done') {
            $result[1] = ceil($result[1]);
        }
        return $result;
    }
}