stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

Float to string with fixed precision

Open svenroy opened this issue 3 months ago • 3 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

svenroy avatar Mar 16 '24 15:03 svenroy

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

lpil avatar Mar 16 '24 16:03 lpil

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

Davidjustice28 avatar Mar 23 '24 20:03 Davidjustice28

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

markholmes avatar Mar 24 '24 01:03 markholmes