Question

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);
},
Was it helpful?

Solution 2

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';

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top