I am a new programmer and I am trying to write a funtion which does an equation then determines if it is a float, or decimal number. If it is then it needs to be rounded up to the next whole number. Any suggestions?
Printable View
I am a new programmer and I am trying to write a funtion which does an equation then determines if it is a float, or decimal number. If it is then it needs to be rounded up to the next whole number. Any suggestions?
I'm assuming your input is text representing a number. Attempt to convert it to a double, if that fails attempt to convert it to an int. If the first attempt fails, it's not a floating-point value; if the second attempt fails, it's not an integral type either.
Since it will always round up could I use the ceil function in the cmath library?
Sure. But don't gloss over the input section. Actually, it might be better to check for integer before floating point since something like "1234" is both.