Node.js Buffer.writeFloatLE() Method (original) (raw)

Last Updated : 13 Oct, 2021

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:

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

javascript `

// Node.js program to demonstrate the
// Buffer.writeFloatLE() method

// Creating a buffer of size 6 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:

javascript `

// Node.js program to demonstrate the
// Buffer.writeFloatLE() method

// Creating a buffer of size 6 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