Why Does JS Coerce X.00000 to an Int?
Posted: Tue Aug 27, 2019 5:21 pm
I've been having a nightmare trying to place notes through the JS LiveAPI.
If i sent a note position of 0.0 like this: parseFloat(Number(0.0).toFixed(5)) JS will output it as an Int, 0, which Ableton then kicks up a fuss about as it's expecting a float for the position argument. Ruins my whole message and kills the function call.
I finally solved it using toPrecision() method of Number like this: parseFloat(0.0).toPrecision(5), and it will work. But what the hell... It's only 0.00 that makes any trouble, all other 'integer' positions work just fine using toFixed() inside parseFloat().
I initially started using parseFloat() and toFixed() because i was getting scientific notated numbers occasionally, which would then mess up my messages. I also noticed that the msg_float() built-in function of JS was chopping off significant digits in the fractional part of my numbers, so had to send them in as strings to get the full 4-5 digits i wanted. Bloody pain in the arse. I only even started using JS cos sending the messages in series to live.object was giving me an even worse headache what with the stupid threading in Max.
Bit of a rant, but does anybody know why this stupid number massaging happens inside JS>?
If i sent a note position of 0.0 like this: parseFloat(Number(0.0).toFixed(5)) JS will output it as an Int, 0, which Ableton then kicks up a fuss about as it's expecting a float for the position argument. Ruins my whole message and kills the function call.
I finally solved it using toPrecision() method of Number like this: parseFloat(0.0).toPrecision(5), and it will work. But what the hell... It's only 0.00 that makes any trouble, all other 'integer' positions work just fine using toFixed() inside parseFloat().
I initially started using parseFloat() and toFixed() because i was getting scientific notated numbers occasionally, which would then mess up my messages. I also noticed that the msg_float() built-in function of JS was chopping off significant digits in the fractional part of my numbers, so had to send them in as strings to get the full 4-5 digits i wanted. Bloody pain in the arse. I only even started using JS cos sending the messages in series to live.object was giving me an even worse headache what with the stupid threading in Max.
Bit of a rant, but does anybody know why this stupid number massaging happens inside JS>?