Open In App

Node.js Buffer.writeDoubleLE() Method

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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 accepts 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 a 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
const 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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads