To do rounding up in truncating arithmetic, simply add (denom-1)
to the numerator.
Example, rounding down:
N/2
M/5
K/16
Example, rounding up:
(N+1)/2
(M+4)/5
(K+15)/16
To do round-to-nearest, add (denom/2)
to the numerator (halves will round up):
(N+1)/2
(M+2)/5
(K+8)/16
More Related Contents:
- create a file with prefix =file1 followed by the random number
- Why to code a script which will check if some package is installed in linux and if not then install it?
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Aborting a shell script if any command returns a non-zero value
- Shell script: Run function from script over ssh
- How can I quickly sum all numbers in a file?
- Bash script process substitution Syntax error: “(” unexpected
- Redirect STDERR / STDOUT of a process AFTER it’s been started, using command line?
- What is the difference between using `sh` and `source`?
- Setting environment variables in Linux using Bash
- How can I loop over the output of a shell command?
- Why does /bin/sh behave differently to /bin/bash even if one points to the other?
- [ :Unexpected operator in shell programming [duplicate]
- Does “argument list too long” restriction apply to shell builtins?
- Given two directory trees, how can I find out which files differ by content? [closed]
- Run a shell command when a file is added
- Using the passwd command from within a shell script
- Add a bash script to path
- Get last dirname/filename in a file path argument in Bash
- Bash script execution with and without shebang in Linux and BSD
- bash command not found when setting a variable
- How do you normalize a file path in Bash?
- Exit code of variable assignment to command substitution in Bash
- Linux/Unix command to determine if process is running?
- Insert multiple lines into a file after specified pattern using shell script
- How do you filter out all unique lines in a file?
- bash, command not found [duplicate]
- How to convert hex to ASCII characters in the Linux shell?
- How to avoid race condition when using a lock-file to avoid two instances of a script running simultaneously?
- Need to remove the count from the output when using “uniq -c” command