query
On this page

floatToString

lib.strings.floatToString

Docs pulled from | This Revision | 43 minutes ago


Convert a float to a string, but emit a warning when precision is lost during the conversion

Inputs

float
1. Function argument

Type

floatToString :: float -> string

Examples

lib.strings.floatToString usage example

floatToString 0.000001
=> "0.000001"
floatToString 0.0000001
=> trace: warning: Imprecise conversion from float to string 0.000000
   "0.000000"

Noogle detected

Implementation

The following is the current implementation of this function.

floatToString = float: let
    result = toString float;
    precise = float == fromJSON result;
  in lib.warnIf (!precise) "Imprecise conversion from float to string ${result}"
    result;