phplaravelcalculatorcalculation

Laravel counted price issue


i'm working in laravel but really some help. I'm trying to find the price of a discounted produkt.

'totalPrice' => 1 - $request->input('discount')*$request->input('price'),

( 0.2 is discount value from table )

Right now it says 1 - 0.2 * price

I want it to be 1 - 0.2 * price = 0.8 * price


Solution

  • You need to follow the PEMDAS Rules,

    wherein you need to include () Parentheses in the ( 1 - $request->input('discount') ) and then multiply its result.

    Just like this.

    'totalPrice' => ( 1 - $request->input('discount') ) * $request->input('price')
    

    In this equation the system will substract first and then multiply its result.