How to convert number to String

Viewed 1373

Is there a function like number -> String in Elm which formats number to String? Not looking for specific Int or Float type but a general converting function for "typeclass" number.

3 Answers

No.


Generally the number typeclass exists mostly so that mathematical operators work for both Int and Float. I would recommend not trying to program generically against number in your own code, but just pick the appropriate one (that's usually Float, unless you're counting).

While individual methods exist to convert from float/int to string, there is no common method to do so since version 0.19 of elm. As of today, you can use the Debug.toString method to do so. But the debug module does not work for production builds.

So, if your end goal is to make a production ready code, you will have to make your own code to typecast, else Debug.toString should work for you.

Related