Node.js Buffer.writeFloatLE() Method
The Buffer.writeFloatLE() method is an inbuilt application programming interface of class Buffer with in Buffer module that writes a value to the buffer at the specified offset with the specified little endian format. Note that the value must be a valid 32-bit float.
Syntax:
Buffer.writeFloatLE( 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. The value of offset lies between 0 to buf.length-4. Its default value is 0.
Return value: It returns the offset along with number of bytes written.
Example 1:
const buf = Buffer.allocUnsafe(10);
buf.writeFloatLE(0x1234567890ab, 0);
console.log(buf);
|
Output:
<Buffer b4 a2 91 55 62 01 00 00 38 e0>
Example 2:
const buf = Buffer.allocUnsafe(4);
buf.writeFloatLE(0xabcafebabe, 0);
console.log(buf);
|
Output:
<Buffer ff ca 2b 53>
Note: The above program will compile and run by using the node index.js
command.
Reference: https://nodejs.org/api/buffer.html#buffer_buf_writefloatle_value_offset
Last Updated :
13 Oct, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...