JavaScript DataView getFloat64() Method



The JavaScript DataViewgetFloat64()method is used to retrieve an 8-byte floating point number starting at the specified byte offset within this DataView. It is possible to retrievemultiple bytevalues 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 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 getFloat64() method −

getFloat64(byteOffset, littleEndian)

Parameters

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

  • byteOffset − The position in the DataView from which to read the data.
  • littleEndian − It indicates whether the data is stored in little-or-big endian format.

Return value

This method returns a number value.

Example 1

The following program demonstrates the usage of the JavaScript DataView getFloat64() method.






Output

The above program returns the store value as −

The byte offset: 0
Value: 433.45
The getFloat64() method: 4.667261456827042e-62

Example 2

The following is another example of the JavaScript DataView getFloat64() method. We use this method to retrieve a 64-bit floating point number starting at the specified byte offset 1 within this DataView.






Output

After executing the above program, it will store the specified floating point number within the data view.

The byte offset: 1
Value: 3.141592653589793
The store value: 3.207375630676366e-192

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
The value: 16.34
Error: RangeError: Offset is outside the bounds of the DataView
Advertisements