Skip to content
Related Articles

Related Articles

Improve Article

Node.js | Buffer.writeDoubleLE() Method

  • Last Updated : 26 May, 2021

The Buffer.writeDoubleLE() Method is an inbuilt application programming interface of class Buffer within Buffer module that writes a value to the buffer at the specified offset with the specified endian format. Note that the value must be a valid 64-bit double.
Syntax: 
 

Buffer.writeDoubleLE(value, offset)

Parameters: This method accept two parameters as mentioned above and described below: 
 

  • value: This parameter holds a number that is to be written to the buffer.
  • offset: This parameter holds the number(integer) of bytes to skip before starting to write.

Return value: It returns the offset along with number of bytes written.
Example 1: 
 

javascript




// Node.js program to demonstrate the
// Buffer.writeDoubleLE() method
 
// Create a buffer
const buf = Buffer.allocUnsafe(8);
 
// Use writeDoubleLE() method
buf.writeDoubleLE(123.456, 0);
 
// Display the buffer value
console.log(buf);

Output: 
 



<Buffer 77 be 9f 1a 2f dd 5e 40>

Example 2: 
 

javascript




// Node.js program to demonstrate the
// Buffer.writeDoubleLE() method
 
// Create a buffer
var buf = Buffer.allocUnsafe(16);
 
// Use writeDoubleLE() method
buf.writeDoubleLE(0xcafebabe, 4);
 
// Display the buffer value
console.log(buf);

Output: 
 

<Buffer 28 83 db 7c 00 00 c0 57 d7 5f e9 41 00 00 00 00>

Reference:https://nodejs.org/api/buffer.html#buffer_buf_writedoublele_value_offset
 

My Personal Notes arrow_drop_up
Recommended Articles
Page :