0

I have a Galleria (galleria.io) that works when the code looks like this:

Galleria.run('.galleria', {
  flickr: 'set:72157640607666844', }

But when I try to set the set number as a variable, it breaks with a "Fatal error: 1 fail: Photoset not found"

var fakeVar = 72157640607666844
  Galleria.run('.galleria', {
  flickr: 'set:' + fakeVar, }

Any thoughts on how to get this to work?

FYI: I looked at console.log('set:' + fakeVar), and it certainly is returning set:72157640607666844. Initially, I thought it was because it was returning the set without quotes, but I know this is not the case, because if I do " 'set:"+ fakeVar + " ' ", I get a no method error for 'set.

Also if it's helpful, this is the Galleria program code that defines the set method:

set: function( photoset_id, callback ) {
    return this._find({
        photoset_id: photoset_id,
        method: 'flickr.photosets.getPhotos'
    }, callback);
},
james
  • 3,989
  • 8
  • 47
  • 102
  • 1
    `alert(fakeVar)` – surprise! Use a _string_ value. – CBroe Feb 28 '14 at 18:36
  • 1
    This is an example of things looking like a number but not actually being something you should use a number for in code. If you don't do math with your number you should use a string to represent it. – Coenwulf Feb 28 '14 at 18:43

2 Answers2

2

Try this in your JavaScript console:

alert('set:' + 72157640607666844); alerts "set:72157640607666850" for me
parseInt("72157640607666844") // returns 72157640607666850 for me

JavaScript can't deal with numbers this large. It uses double-precision floating-point internally to represent numbers, and 72157640607666850 is as closed to 72157640607666844 as JavaScript can manage. You'll need to leave it in string format or use a library like BigNumber to deal with this.

Here's more information on representing Integers in a variety of languages.

1

72157640607666844 is too significant of a Number for JavaScript to store completely:

console.log(72157640607666844);
//          72157640607666850

To avoid issues with precision, you can wrap the literal in quotes so it's a String instead:

var fakeVar = '72157640607666844';
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199