javascript - parseFloat returns NaN -


i'm trying rid of currency sign in order calculate new price using parsefloat, returns nan reason.

var priceperuser = "£19.99"; priceperuser = parsefloat(priceperuser) * 3; console.log(priceperuser); //returns nan 

parsefloat() work on string until finds non-numeric value. £ first character, hence there no number parse. need remove before call parsefloat():

var priceperuser = "£19.99"; priceperuser = parsefloat(priceperuser.replace('£', '')) * 3; console.log(priceperuser); 

if require 2dp precision, use tofixed(2):

console.log(priceperuser.tofixed(2)); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -