0

I have POS system made in codigniter. I have three fields

  1. Cash Received
  2. Cash Pending
  3. Balance

I have payment edit form that open in a model and display values. I am getting values with these code

$.ajax({
  url: 'payment/editPaymentByJason?id=' + iid,
  method: 'GET',
  data: '',
  dataType: 'json',
}).success(function (response) {
  var cr = response.cash_received;        
  var cp = response.cash_pending;        
  var b = cr - cp;

but the output is not what i need. Let suppose

Cash Received = 500
Cash Pending = 200

Instead of showing 300 in the balance field This this function shows 500200 in the balance field.

I want to how i add or subtract value in var b ?

Mikev
  • 2,012
  • 1
  • 15
  • 27
Anderson
  • 19
  • 7

1 Answers1

0

You can only make calculations with number values.

cr and cp are probably strings, so you need to convert them with parseInt() or parseFloat (when you want to use decimal values).

Doc
  • 177
  • 1
  • 3
  • 14