Add 0.5
before casting to int
. If your system supports it, you can call the C99 round()
function, but I prefer to avoid it for portability reasons.
More Related Contents:
- Strange behaviour of the pow function
- pow() seems to be out by one here
- Does pow() work for int data type in C? [duplicate]
- pow() cast to integer, unexpected result
- How to pass arguments
- Why when I print it appears 80 for *str in decimal (letter P in ASCII)?
- C – Trouble calling a function
- In c, read floats from one line, seperated by space [duplicate]
- What is the purpose of static keyword in array parameter of function like “char s[static 10]”?
- How to change entry point of C program with gcc?
- Call Go functions from C
- Sending file descriptor by Linux socket
- Can FFmpeg be used as a library, instead of a standalone program?
- What is it with printf() sending output to buffer?
- Sleep function in Windows, using C
- C – Accessing data AFTER memory has been free()ed?
- Parse string into argv/argc
- allocate matrix in C
- Macro expansion and stringification: How to get the macro name (not its value) stringified using another macro?
- Read input.txt file and also output.bmp file from terminal (C-programming)
- Why is memcmp so much faster than a for loop check?
- how to quit the blocking of xlib’s XNextEvent
- Different way of accessing array elements in C
- winapi: CreateProcess but hide the process’ window?
- What’s the proper implementation for hardware emulation?
- Size of pid_t, uid_t, gid_t on Linux
- Why does the Win32-API have so many custom types?
- Signed bit field represetation
- What is the effect of second argument in _builtin_prefetch()?
- How many chars can be in a char array?