How can I best convert an integer to a floating point value without assigning to a variable?

delphi

Solution

It's academic and I'd use a function or * 1.0 but this works

Format('Theoretical peak scaling %6.2f', [Double(Variant(ThreadCount))])

Problem

I would like to know how to convert from an integer to a floating point value, without assigning to an intermediate variable. The code in question looks like this: ``` Format('Theoretical peak scaling %6.2f', [ThreadCount]) ``` This obviously fails at runtime because `ThreadCount` is an integer. I tried the obvious ``` Format('Theoretical peak scaling %6.2f', [Double(ThreadCount)]) ``` and the compiler rejects that with ``` E2089 Invalid typecast ``` I know I can write ``` Format('Theoretical peak scaling %6.2f', [ThreadCount*1.0]) ``` but that reads poorly and will just tempt a future maintainer to remove the multiplication in error. Does anyone know of a clean way to do this without an intermediate variable, and in way that makes the codes intent clear to future readers?

Original source