gleam-lang / stdlib

🎁 Gleam's standard library

Home Page:https://hexdocs.pm/gleam_stdlib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Float to string with fixed precision

svenroy opened this issue · comments

In Javascript, I am able to do:

const value = 0.8999999999
const roundedValueAsString = value.toFixed(2)

console.log(roundedValueAsString) // "0.90"
console.log(typeof roundedValueAsString) // "string"

There is similar behaviour in Elixir

Hello! Good idea, thank you. It would go in the float module and we'd need to determine a name.

@lpil I am currently working on this. How do we feel about to_fixed_string or to_string_fixed for the function name?

Since round, truncate, and to_string already exist, I think to_fixed_string sounds like a good name. Anyone else have ideas?