Hey again,
is there anyway I can round up a double, like:
2367.4242 to a long 2367
Hey again,
is there anyway I can round up a double, like:
2367.4242 to a long 2367
Yes. There is a search feature for this forum.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Ok, Thanks for pointing that out.
I noticed there was supposed to be a round function in the math lib, but I don't appear to have it.
I looked at another few past posts but I am still a bit confused , and actually I think I just want to trunicate it...like
double num[i] = 2345.565656 to become
long temp[i] =2345
sorry for all the bother, but my heads not thinking clear with this head cold I have
lol thanks very much so simple!
helped me figure out something harder tho
C will automatically round down, or simply cut off the decimal, if you assign a floating point value to an integer variable. If you wish to round up all the time, simply do that and then add one to the integer. If you wanted to round up or down depending on the value of the floating point variable, you would have to do a slightly more complex system of checking to see if the decimal point is higher or lower than .5
Or you could just add .5:
Code:double d = 1.6, e = 1.3; int x = (int)(d+.5), y = (int)(e+.5); /* x = 2, y = 1 */
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.