@@ -162,8 +162,11 @@ Float.parseFloat("error")->Float.isNaN // true
162162external parseFloat : string => float = "parseFloat"
163163
164164/**
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.
167170See [`parseInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) on MDN.
168171
169172## Examples
@@ -174,10 +177,14 @@ Float.parseInt(" 3.14 ") // 3.0
174177Float.parseInt(3) // 3.0
175178Float.parseInt("3.14some non-digit characters") // 3.0
176179Float.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
177184```
178185*/
179186@val
180- external parseInt : 'a => float = "parseInt"
187+ external parseInt : ( 'a , ~ radix : int = ?) => float = "parseInt"
181188
182189/**
183190`parseIntWithRadix(v, ~radix)` parse the given `v` and returns a float. Leading
@@ -196,23 +203,32 @@ Float.parseIntWithRadix("12", ~radix=13) // 15.0
196203Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true
197204```
198205*/
206+ @deprecated ("Use `parseInt` instead" )
199207@val
200208external parseIntWithRadix : ('a , ~radix : int ) => float = "parseInt"
201209
202210/**
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.
205214See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) on MDN.
206215
207216## Examples
208217
209218```rescript
210219Float.toExponential(1000.0) // "1e+3"
211220Float.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.
212228```
213229*/
214230@send
215- external toExponential : float => string = "toExponential"
231+ external toExponential : ( float , ~ digits : int = ?) => string = "toExponential"
216232
217233/**
218234`toExponential(v, ~digits)` return a `string` representing the given value in
@@ -231,23 +247,31 @@ Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3"
231247
232248- `RangeError`: If `digits` less than 0 or greater than 10.
233249*/
250+ @deprecated ("Use `toExponential` instead" )
234251@send
235252external toExponentialWithPrecision : (float , ~digits : int ) => string = "toExponential"
236253
237254/**
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.
240258See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) on MDN.
241259
242260## Examples
243261
244262```rescript
245263Float.toFixed(123456.0) // "123456.00"
246264Float.toFixed(10.0) // "10.00"
265+ Float.toFixed(300.0, ~digits=4) // "300.0000"
266+ Float.toFixed(300.0, ~digits=1) // "300.0"
247267```
268+
269+ ## Exceptions
270+
271+ - `RangeError`: If `digits` is less than 0 or larger than 100.
248272*/
249273@send
250- external toFixed : float => string = "toFixed"
274+ external toFixed : ( float , ~ digits : int = ?) => string = "toFixed"
251275
252276/**
253277`toFixedWithPrecision(v, ~digits)` return a `string` representing the given
@@ -266,24 +290,32 @@ Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0"
266290
267291- `RangeError`: If `digits` is less than 0 or larger than 100.
268292*/
293+ @deprecated ("Use `toFixed` instead" )
269294@send
270295external toFixedWithPrecision : (float , ~digits : int ) => string = "toFixed"
271296
272297/**
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.
276300See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
277301
278302## Examples
279303
280304```rescript
281305Float.toPrecision(100.0) // "100"
282306Float.toPrecision(1.0) // "1"
307+ Float.toPrecision(100.0, ~digits=2) // "1.0e+2"
308+ Float.toPrecision(1.0, ~digits=1) // "1"
283309```
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.
284316*/
285317@send
286- external toPrecision : float => string = "toPrecision"
318+ external toPrecision : ( float , ~ digits : int = ?) => string = "toPrecision"
287319
288320/**
289321`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.
304336ECMA-262 only requires a precision of up to 21 significant digits.
305337
306338*/
339+ @deprecated ("Use `toPrecision` instead" )
307340@send
308341external toPrecisionWithPrecision : (float , ~digits : int ) => string = "toPrecision"
309342
@@ -319,7 +352,7 @@ Float.toString(-1000.0) // "-1000"
319352```
320353*/
321354@send
322- external toString : float => string = "toString"
355+ external toString : ( float , ~ radix : int = ?) => string = "toString"
323356
324357/**
325358`toStringWithRadix(v, ~radix)` return a `string` representing the given value.
@@ -338,6 +371,7 @@ Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c"
338371
339372`RangeError`: if `radix` is less than 2 or greater than 36.
340373*/
374+ @deprecated ("Use `toString` with `~radix` instead" )
341375@send
342376external toStringWithRadix : (float , ~radix : int ) => string = "toString"
343377
0 commit comments