val toFixedWithPrecision : float ->digits:int -> string
Formats a float using fixed point notation
digits specifies how many digits should appear after the decimal point. The value must be in the range [0, 20] (inclusive). Defaults to 0.
Returns a string representing the given value in fixed-point notation (usually)
The output will be rounded or padded with zeroes if necessary.
raisesRangeError
if digits is not in the range [0, 20] (inclusive)
(* prints "12345.7" (note the rounding) *)
let _ = Js.log (Js.Float.toFixedWithPrecision 12345.6789 ~digits:1)
(* prints "0.00" (note the added zeroes) *)
let _ = Js.log (Js.Float.toFixedWithPrecision 0. ~digits:2)
Returns a string representing the given value in fixed-point (usually)
toPrecision differs from toFixed in that the former will format the number with full precision, while the latter will not output any digits after the decimal point.
raisesRangeError
if digits is not in the range accepted by this function (what do you mean "vague"?)
(* prints "12345.6789" *)
let _ = Js.log (Js.Float.toPrecision 12345.6789)
(* print "1.2e+21" *)
let _ = Js.log (Js.Float.toPrecision 1.2e21)
val toPrecisionWithPrecision : float ->digits:int -> string
Formats a float using some fairly arbitrary rules
digits specifies how many digits should appear in total. The value must between 0 and some arbitrary number that's hopefully at least larger than 20 (for Node it's 21. Why? Who knows).
Returns a string representing the given value in fixed-point or scientific notation
The output will be rounded or padded with zeroes if necessary.
toPrecisionWithPrecision differs from toFixedWithPrecision in that the former will count all digits against the precision, while the latter will count only the digits after the decimal point. toPrecisionWithPrecision will also use scientific notation if the specified precision is less than the number for digits before the decimal point.
raisesRangeError
if digits is not in the range accepted by this function (what do you mean "vague"?)
(* prints "1e+4" *)
let _ = Js.log (Js.Float.toPrecisionWithPrecision 12345.6789 ~digits:1)
(* prints "0.0" *)
let _ = Js.log (Js.Float.toPrecisionWithPrecision 0. ~digits:2)