+1 for the function
cast to (float) is not needed, will be done automatically as it is multiplied by a float.
(It might even be preferred to keep it an int, never tested)
Alert: conflict between code and comment
// the raw ADC value is 0 to 2023 for a range of 5 Volt.
float voltage = (float) analogRead(pin) * 5.0 / 1023.0;