Javascript syntax error

Asked

Viewed 270 times

1

I came across the following syntax error in javascript/jquery

Uncaught Syntaxerror: Unexpected number

and I’m using the plugin Number.prototype.formatMoney might have something related?

Plugin

Number.prototype.formatMoney = function(c, d, t){
var n = this, 
    c = isNaN(c = Math.abs(c)) ? 2 : c, 
    d = typeof d == "undefined" ? "." : d, 
    t = typeof t == "undefined" ? "," : t, 
    s = n < 0 ? "-" : "", 
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
    j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };

Calling method

$("#dados #total").html("R$ "+(parseFloat(total)).formatMoney(2, ',', '.'));

Know how to solve?

  • 1

    Dude, I created a fiddle (http://jsfiddle.net/1dqhqu4s/) with its code and it works fine. It is very likely that the problem is in another location, could include some more of your code?

  • @Edgarmunizberlinck the code is too big, I’ll see some likely snippets that might be wrong, but you know specifically why this error happens Uncaught SyntaxError: Unexpected number ? if you can also give some example of occasion when this mistake happens, thank you :)

  • Dude, this is really syntax error. See the EDIT of my answer. If it doesn’t help yell there.

1 answer

4

Specifically answering your question: Not. Your code in question works smoothly.

Proof: http://jsfiddle.net/1dqhqu4s/

Given the section below:

$("#dados #total").html("R$ "+(parseFloat(total)).formatMoney(2, ',', '.'));

Independent of variable value total the code works smoothly.

The only thing that could cause you problems would be the variable total not being defined, but this would only give problems if you are using the Strict mode. Besides the error would be another and not the one you reported to us.

EDIT This error in question may be caused by an error in the syntax of your code itself. You probably didn’t close a key, bracket or parenthesis; Forgot a dot and comma or something.

  • It can be error in the same total variable, because when I enter with a user works normal but when I enter another error happens

  • @Silvioandorinha Cara, this is a mistake true bug. Take a closer look at your code which should have some Zica. Have a coffee first.

  • Thanks for the tip of the kk coffee, I will take a look yes and then put the solution when I find.. Thanks +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.