If I have a float like 3.75, how can I split it into the integer 3 and the float 0.75?
Do I have to convert the float into a string, and then split the string by “.”, and then convert the parts into integers and floats again, or is there a more elegant or “right” way to do this?
As mentioned you can use
3.75.to_ito get the integer.An alternate way to get the remainder is using the
%operator eg.3.75 % 1