aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/dataview/getfloat32/index.html
blob: b43d4df38ccc15bed3d9c0d398bff4864fe83549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
title: DataView.prototype.getFloat32()
slug: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32
tags:
  - DataView
  - getFloat32
translation_of: Web/JavaScript/Reference/Global_Objects/DataView/getFloat32
---
<div>{{JSRef}}</div>

<p><strong><code>getFloat32()</code></strong>方法从相对于{{jsxref("DataView")}} 的起始位置偏移 n 个字节处获取一个32-bit浮点数(单精度浮点数,4个字节).</p>

<div>{{EmbedInteractiveExample("pages/js/dataview-getfloat32.html")}}</div>



<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>dataview</var>.getFloat32(byteOffset [, littleEndian])</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt>byteOffset</dt>
 <dd>偏移量, 单位为字节, 为从视图的开始位置到读取数值的位置的偏移。</dd>
 <dt>littleEndian</dt>
 <dd>{{optional_inline}} 表示这个32位浮点数是否以 {{Glossary("Endianness", "little- or big-endian")}} 格式存储,如果设置为 false 或者不指定,将用big-endian格式读取数值。</dd>
</dl>

<h3 id="返回">返回</h3>

<dl>
 <dd>一个带符号的32位浮点数。</dd>
</dl>

<h3 id="抛出错误">抛出错误</h3>

<dl>
 <dt>{{jsxref("RangeError")}}</dt>
 <dd>如果byteOffset 设置导致读数值时超出了视图的末尾就会抛出错误。</dd>
</dl>

<h2 id="说明">说明</h2>

<dl>
 <dd>没有对齐约束; 多字节值可以从任何偏移处获取。</dd>
</dl>

<h2 id="例子">例子</h2>

<pre class="brush:js">var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.getFloat32(1); // 0
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Typed Array')}}</td>
   <td>{{Spec2('Typed Array')}}</td>
   <td>Superseded by ECMAScript 6.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-dataview.prototype.getfloat32', 'DataView.prototype.getFloat32')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition in an ECMA standard.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-dataview.prototype.getfloat32', 'DataView.prototype.getFloat32')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>



<p>{{Compat("javascript.builtins.DataView.getFloat32")}}</p>

<h2 id="另见">另见</h2>

<ul>
 <li>{{jsxref("DataView")}}</li>
 <li>{{jsxref("ArrayBuffer")}}</li>
</ul>