How to convert an int into a float

Hi

I am facing a pretty simple issue, I have a parameter given as an int and I need to convert it to a float to pass it to another module.

What’s the syntax to do this in Nix? I see that adding 0.0 to the int convert it but it does not look very clean.

There doesn’t seem to be a function for this in the built-ins, nor is there any documentation of such a feature, except the mechanism you use: Data Types - Nix Reference Manual

So I think your solution is correct without any other information.

That said, why are you converting an int to a float? Given the auto conversion, I think the only reason to do such a thing would be for presentation, at which point surely you just need a way to format an int into a string with decimals?

It is exactly for a presentation problem. I use one value for 3 modules, one needs it as a float, the other as an int. Both use the vale it in configuration files waiting for a string with a fractional part and without one for the other. I cannot change this easily and is not extremely important but I wanted to do it the most nix idiomatic way as possible.