My problem is this: I am retrieving a Json object from localStorage via Javascript, and wanted to add a value to one of these attributes, and then save the evolta object to local storage. However, when doing the operation: object.attribute = object.attribute + aValueNumeric; what happens is that the values are concatenated in the attribute. That is, instead of 1 + 1 result in two, the result is saved in Json as "11".
In this example, the client's current balance was 122.00 and I tried to add 8772.99.
The two leading zeros are because I have not been able to format the right pattern yet.
Here is my code:
function processaConfirmDep(){
var valor = document.getElementById('valorDeposito');
var favorecido = document.getElementById('nomeFav');
var objDep;
var cliente = localStorage.getItem(favorecido.value);
var clienteConta = JSON.parse(cliente);
var agenciaFav = clienteConta.agencia;
var contaFav = clienteConta.conta;
objDep = {
id : "12",
agenciaFav : agenciaFav.value,
contaFav : contaFav.value,
valor : valor.value
}
clienteConta.saldo = clienteConta.saldo+valor.value;
var clienteDeposito = createMyObject("DepositoLucas", [clienteConta, objDep]);
localStorage["DepositoLucas"] = JSON.stringify(clienteDeposito);
localStorage[clienteConta.nome] = JSON.stringify(clienteConta);
}
Result in the local Storage. (See the "Lucas" key object, "balance" attribute):
{"DepositoLucas":[{"nome":"Lucas","agencia":"33333","conta":"4123","saldo":"0122,008772,99"},{"id":"12","valor":"8772,99"}]}
Lucas {"nome":"Lucas","agencia":"33333","conta":"4123","saldo":"0122,008772,99"}