Right now I'm working on a ledger-type program in a web application. I'm using angularJS to handle the events, but it's raw Javascript that handles the actual calculation
var onEntriesSuccess = function(data) {
    var sum = 0;
    var isDebit = ($scope.account.active == "D" ? true : false);
    angular.forEach(data, function(value, key){
        sum += (isDebit ? value.debit - value.credit : value.credit - value.debit);
        value.balance = sum;
    });
    $scope.entries = data;
}
Which seems to work fine; however, while running it against my test case I find that it fails because when the sum = 10496.82 and attempts to subtract 6912.00 it comes out with
3584.8199999999997
I've never encountered an error like this before, at first I thought it was floating point and switched the value from 6912.02 to 6912.00. However, that doesn't seem to fix anything. Could anyone please explain this? Thanks
 
     
     
    