javascript - JS Function "Object expected At line 2 character 0" -


i'm building plan file xmpie uplan. javascript functions allowed, learning js, thought take advantage of them. seem friendlier proprietary qlingo functions. don't think should matter though, js. see problem js?

function cents(p) { var monfor = tostring(parsefloat(math.round(p * 100) / 100).tofixed(2)); return monfor.slice(-2); } 

the purpose of code return cents in price.

here supposed going on: first make sure number has 2 decimal places , convert string. slice off last 2 digits of string leaving me 2 digit integer string number of pennies in price. flow cents portion of price field cents in superscript. (i have function uses floor kill sub dollar part of price populates dollar part of price.) error on function is:

error:        cents: error occurred while executing function script.  description: object expected @ line 2 character 0. 

thanks in advance help!

var numtoparse = parsefloat(math.round(p * 100) / 100).tofixed(2);  var monfor = numtoparse.tostring(); return monfor.slice(-2); 

you using 2 string in wrong way.

as mentioned in comments, didnt know this, dont need parse string tofixed() parses itself.

var monfor = parsefloat(math.round(p * 100) / 100).tofixed(2); return monfor.slice(-2); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -