@@ -162,8 +162,11 @@ Float.parseFloat("error")->Float.isNaN // true
162
162
external parseFloat: string => float = "parseFloat"
163
163
164
164
/**
165
- `parseInt(v)` parse the given `v` and returns a float. Leading whitespace in
166
- `v` is ignored. Returns `NaN` if `v` can't be parsed.
165
+ `parseInt(v, ~radix=?)` parse the given `v` and returns a float. Leading
166
+ whitespace in this argument `v`is ignored. `radix` specifies the radix base to
167
+ use for the formatted number. The value must be in the range [2, 36] (inclusive).
168
+ Returns `NaN` if `v` can't be parsed and `radix` is smaller than 2 or bigger
169
+ than 36.
167
170
See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) on MDN.
168
171
169
172
## Examples
@@ -174,10 +177,14 @@ Float.parseInt(" 3.14 ") // 3.0
174
177
Float.parseInt(3) // 3.0
175
178
Float.parseInt("3.14some non-digit characters") // 3.0
176
179
Float.parseInt("error")->Float.isNaN // true
180
+ Float.parseInt("10.0", ~radix=2) // 2.0
181
+ Float.parseInt("15 * 3", ~radix=10) // 15.0
182
+ Float.parseInt("12", ~radix=13) // 15.0
183
+ Float.parseInt("17", ~radix=40)->Float.isNaN // true
177
184
```
178
185
*/
179
186
@val
180
- external parseInt: 'a => float = "parseInt"
187
+ external parseInt: ('a, ~radix: int=?) => float = "parseInt"
181
188
182
189
/**
183
190
`parseIntWithRadix(v, ~radix)` parse the given `v` and returns a float. Leading
@@ -196,23 +203,32 @@ Float.parseIntWithRadix("12", ~radix=13) // 15.0
196
203
Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true
197
204
```
198
205
*/
206
+ @deprecated("Use `parseInt` instead")
199
207
@val
200
208
external parseIntWithRadix: ('a, ~radix: int) => float = "parseInt"
201
209
202
210
/**
203
- `toExponential(v)` return a `string` representing the given value in exponential
204
- notation.
211
+ `toExponential(v, ~digits=?)` return a `string` representing the given value in
212
+ exponential notation. `digits` specifies how many digits should appear after
213
+ the decimal point.
205
214
See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.
206
215
207
216
## Examples
208
217
209
218
```rescript
210
219
Float.toExponential(1000.0) // "1e+3"
211
220
Float.toExponential(-1000.0) // "-1e+3"
221
+ Float.toExponential(77.0, ~digits=2) // "7.70e+1"
222
+ Float.toExponential(5678.0, ~digits=2) // "5.68e+3"
223
+ ```
224
+
225
+ ## Exceptions
226
+
227
+ - `RangeError`: If `digits` less than 0 or greater than 10.
212
228
```
213
229
*/
214
230
@send
215
- external toExponential: float => string = "toExponential"
231
+ external toExponential: ( float, ~digits: int=?) => string = "toExponential"
216
232
217
233
/**
218
234
`toExponential(v, ~digits)` return a `string` representing the given value in
@@ -231,23 +247,31 @@ Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3"
231
247
232
248
- `RangeError`: If `digits` less than 0 or greater than 10.
233
249
*/
250
+ @deprecated("Use `toExponential` instead")
234
251
@send
235
252
external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential"
236
253
237
254
/**
238
- `toFixed(v)` return a `string` representing the given value using fixed-point
239
- notation.
255
+ `toFixed(v, ~digits=?)` return a `string` representing the given
256
+ value using fixed-point notation. `digits` specifies how many digits should
257
+ appear after the decimal point.
240
258
See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.
241
259
242
260
## Examples
243
261
244
262
```rescript
245
263
Float.toFixed(123456.0) // "123456.00"
246
264
Float.toFixed(10.0) // "10.00"
265
+ Float.toFixed(300.0, ~digits=4) // "300.0000"
266
+ Float.toFixed(300.0, ~digits=1) // "300.0"
247
267
```
268
+
269
+ ## Exceptions
270
+
271
+ - `RangeError`: If `digits` is less than 0 or larger than 100.
248
272
*/
249
273
@send
250
- external toFixed: float => string = "toFixed"
274
+ external toFixed: ( float, ~digits: int=?) => string = "toFixed"
251
275
252
276
/**
253
277
`toFixedWithPrecision(v, ~digits)` return a `string` representing the given
@@ -266,24 +290,32 @@ Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0"
266
290
267
291
- `RangeError`: If `digits` is less than 0 or larger than 100.
268
292
*/
293
+ @deprecated("Use `toFixed` instead")
269
294
@send
270
295
external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed"
271
296
272
297
/**
273
- `toPrecision(v)` return a `string` representing the giver value with precision.
274
- This function omits the argument that controls precision, so it behaves like
275
- `toString`. See `toPrecisionWithPrecision` to control precision.
298
+ `toPrecision(v, ~digits=?)` return a `string` representing the giver value with
299
+ precision. `digits` specifies the number of significant digits.
276
300
See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
277
301
278
302
## Examples
279
303
280
304
```rescript
281
305
Float.toPrecision(100.0) // "100"
282
306
Float.toPrecision(1.0) // "1"
307
+ Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
308
+ Float.toPrecision(1.0, ~digits=1) // "1"
283
309
```
310
+
311
+ ## Exceptions
312
+
313
+ - `RangeError`: If `digits` is not between 1 and 100 (inclusive).
314
+ Implementations are allowed to support larger and smaller values as well.
315
+ ECMA-262 only requires a precision of up to 21 significant digits.
284
316
*/
285
317
@send
286
- external toPrecision: float => string = "toPrecision"
318
+ external toPrecision: ( float, ~digits: int=?) => string = "toPrecision"
287
319
288
320
/**
289
321
`toPrecisionWithPrecision(v, ~digits)` return a `string` representing the giver value with
@@ -304,6 +336,7 @@ Implementations are allowed to support larger and smaller values as well.
304
336
ECMA-262 only requires a precision of up to 21 significant digits.
305
337
306
338
*/
339
+ @deprecated("Use `toPrecision` instead")
307
340
@send
308
341
external toPrecisionWithPrecision: (float, ~digits: int) => string = "toPrecision"
309
342
@@ -319,7 +352,7 @@ Float.toString(-1000.0) // "-1000"
319
352
```
320
353
*/
321
354
@send
322
- external toString: float => string = "toString"
355
+ external toString: ( float, ~radix: int=?) => string = "toString"
323
356
324
357
/**
325
358
`toStringWithRadix(v, ~radix)` return a `string` representing the given value.
@@ -338,6 +371,7 @@ Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
338
371
339
372
`RangeError`: if `radix` is less than 2 or greater than 36.
340
373
*/
374
+ @deprecated("Use `toString` with `~radix` instead")
341
375
@send
342
376
external toStringWithRadix: (float, ~radix: int) => string = "toString"
343
377
0 commit comments