Say I have a float number. If it is an integer (e.g. 1.0, 9.0, 36.0), I want to remove the ".0 (the decimal point and zero)" and write to stdout. For example, the result will be 1, 9, 36. If the float number is a rational number such as 2.5335 and 95.5893, I want the output to be as it was inputted, meaning 2.5335 and 95.5893. Is there a smart way to do this?
Only whether the number has .0 or other digits at decimal places does matter. I can say my question is this: how can I know whether or not a float number is actually an integer?
I want to use this to decide directory names. For example, if I input 9.0 and 2.45, make two directories, dir9 and dir2.45.
1.0
does not have zeroes all the way, or do you want to check only the first few digits, as in your examples? – Devoted0.1 + 0.2 != 0.3
(and other fun consequences of floats being binary rather than decimal)? – Xenolith123456789.123456769 == 123456789.123456783
is true for my installation (both these floats are printed as123456789.12345678
). On another note, for large "integer" floats, you'll lose digits before the decimal point (for my installation,int(123456789123456789.0) - 123456789123456789 == -5
). – Xenolith