0

Here is my code snippet :

    json.iddd = ~~(json.id);
    console.log(typeof(json.iddd)); //shows number

    new ResponseTabView(json.iddd); // backbone view

inside the view i am calling:

this.grid = new Backgrid.Grid({body : this.body, collection :this.collection, columns: this.columns});

I get the following error :

Uncaught TypeError: Object 5229d8fff4ae7a3803000023 has no method 'toFixed'

How to get rid of it?

codeofnode
  • 18,169
  • 29
  • 85
  • 142

2 Answers2

0

In the parameters passed to the Backgrid.Grid, one parameter needs to be of Number type. But the parameter that you are passing is of 'String' type.

String object doesn't have a toFixed() for you to use. Hence the error.

Please console.log the typoof each parameter and also read the docs of Backgrid to see what parameter needs to be of Number type.

Cheers!

Abilash
  • 6,089
  • 6
  • 25
  • 30
  • so how do i convert string into number in javascript. I have json.id into string and and want to convert into number. – codeofnode Sep 15 '13 at 03:29
  • Refer to this question http://stackoverflow.com/questions/5330420/why-cant-i-use-tofixed-on-an-html-input-objects-value – Abilash Sep 15 '13 at 03:31
0

As @Abhilash said , You are using toFixed() on string type Object that will surely result into error Object xyz has no method toFixed.

toFixed is method of number Object not string.

Here is a reference table for you

Number Object Methods

toExponential(x)    Converts a number into an exponential notation
toFixed(x)          Formats a number with x numbers of digits after the decimal point
toPrecision(x)      Formats a number to x length
toString()          Converts a Number object to a string
valueOf()           Returns the primitive value of a Number object

So you need to parse the string into integer using parstInt() or parseFloat()

parseInt(json.iddd).toFixed();   Or
parseFloat(json.iddd).toFixed();
Deepak Ingole
  • 14,912
  • 10
  • 47
  • 79