JavaScript DataView setFloat64() Method



The JavaScript DataView setFloat64() method is used to store a 64-bit floating point number in the 8 bytes (where 1 byte = 8 bits) starting at the specified byte offset within this DataView. It is possible to store multiple byte values at any byte offset within the specified bounds.

A floating point number is a positive or negative whole number with a decimal point. For example, 5.5, 0.25, -103.342, etc.

If the value of the byteOffset parameter falls outside the bounds of the data view, it will throw a 'RangeError' exception.

Syntax

Following is the syntax of the JavaScript DataView setFloat64() method −

setFloat64(byteOffset, value, littleEndian)

Parameters

This method accepts three parameters named 'byteOffset', 'value', and 'littleEndian', which are described below −

  • byteOffset − The position in the DataView where the byte will be stored.
  • value − A 32-bit floating point number that needs to be stored.
  • littleEndian − It indicates whether the data is stored in little-or-big endian format.

Return value

This method returns 'undefined'.

Example 1

The following is the basic example of the JavaScript DataView setFloat64() method.






Output

The above program returns 'undefined' −

The byte offset: 0
Value: 433.45
The setFloat64() method: undefined

Example 2

The following is another example of the JavaScript DataViewsetFloat64()method. We use this method to store 64-bit floating point number (retrieve from) Math.PIstarting at the specified byte1within this DataView.






Output

After executing the above program, it will store the specified floating point number within the DataView and display it as −

The byte offset: 1
Value: 3.141592653589793
The store value: 3.143e-319

Example 3

If the value of the byteOffset parameter falls outside the bounds of this data view, it will throw a 'RangeError' exception.






Output

Once the above program is executed, it will throw a 'RangeError' exception as −

The byte offset: -1
Value: 16.34
RangeError: Offset is outside the bounds of the DataView
Advertisements