View Single Post
Old 12-26-2019, 04:50 PM   #13
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Kythe42 View Post
I suppose I don't fully understand what floating point numbers are or how they apply here since I thought they were just any number with an exponent such as 200 to the power of 10 (not sure how to format the superscript here).
Floating point numbers (often called "real" numbers) are distinguished from integers by having a fractional part. For example, "1" is an integer while "1.5" and "1 2/3" are floats. Exponentials are not directly related to this difference. Whether or not the result of the exponent operation is an integer or a float depends on whether the result has a fractional part.

The format code "d" stands for decimal, aka integer. The format code "f" stands for float. Apparently the code that does the conversion to character (prints) for integer is unable to handle a float. This is understandable because it would need to silently throw away any fraction. The code for "float" is able to handle an integer, understandable because an integer's fractional part is zero. That is why in your case 'f' generally works, while 'd' works only when the result of the divide is an integer (no fraction, e.g. 200/50).

More than you wanted to know.
chaley is offline   Reply With Quote