javascript - Meteor Getting incorrect typeof value on number -
i have form user can create changes record. when form submitted compare previous values new values , record changes made in alter log collection.
i know pulling value of amount field needs converted number before check if has changed. problem after conversion template helper still see's string.
here's code;
var trxcoll = trx.findone(session.get('trx_db_currentid')); // contains _id of trx records on screen var formcoll = thetemplate.findall('.trx_edit'); formcoll.foreach( function(item) { docname = "trxcoll." + item.name; // input names same db field names var value = item.value; if (item.name === "trx_amount") { value = parsefloat(value).tofixed(2); } if (value !== eval(docname)) { console.log(value+ " has type : " + typeof value + " , " + typeof eval(docname) + " has type : " + eval(docname)); } }); input field is- amount: <input type="text" name="trx_amount" value="{{trx_amount}}" id="trx_amount" class="trx_edit">
this in console;
568.00 has type : string , 568 has type : number
also when update datebase -
trx.update({'_id': 'roj4w9jg6htsf8vfj' }, {$set: {'trx_amount': 568.00}})
it shows 568.
javascript meteor
No comments:
Post a Comment