The formula
A fare is base fare plus distance plus time, multiplied by any surge, with tolls and airport fees added. Every serious app uses some version of this.
Why surge exists
When more people want rides than there are drivers, price rises until the two match. It is unpopular and it is the only mechanism that reliably gets a car to arrive.
What to check before confirming
Whether the quoted fare is fixed or an estimate, whether tolls are included, and what the cancellation fee is.