You probably want to have a look at this:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
From this it looks like you should be able to do something like this:
var payload = message.payloadByte()
var doubleView = new Float64Array(payload);
var number = doubleView[0];
This assumes that the payload of the message is a single 64-bit IEEE floating point number
The other possible option is to look at the answer to this previous question :
Read/Write bytes of float in JS
EDIT:
The following code works for me:
function onMessageArrived(message) {
var payload = message.payloadBytes
var length = payload.length;
var buffer = new ArrayBuffer(length);
uint = new Uint8Array(buffer);
for (var i=0; i<length; i++) {
uint[(length-1)-i] = payload[i];
}
var doubleView = new Float64Array(uint.buffer);
var number = doubleView[0];
console.log("onMessageArrived:"+number);
};
Note that I had to reverse the byte order to get the correct output.
EDIT 2
This works better and will decode arbitrary lengths of arrays of doubles:
function onMessageArrived(message) {
var payload = message.payloadBytes
var length = payload.length;
var buffer = new ArrayBuffer(length);
uint = new Uint8Array(buffer);
for (var i=0; i<length; i++) {
uint[i] = payload[i];
}
var dataView = new DataView(uint.buffer);
for (var i=0; i<length/8; i++) {
console.log(dataView.getFloat64((i*8), false));
}
};
(you may need to flip the false to a true at the end of the dataView.getFloat64() depending on the endianness of the sending platform)
Full write up of the code I wrote to get this far can be found here: http://www.hardill.me.uk/wordpress/2014/08/29/unpacking-binary-data-from-mqtt-in-javascript/