docs: update

This commit is contained in:
Dylan Araps 2019-09-24 08:25:03 +03:00
parent dc6de0ef34
commit 48eb245a27

View file

@ -895,16 +895,23 @@ var=$((var2 > var ? var2 : var))
**Example Function:**
```sh
# Usage: is_float "number"
is_float() {
# Usage: is_float "number"
case $1 in
*.*.*|*[!-.0-9]*) ;;
*[0-9].[0-9]*) return 0
esac
return 1
# The test checks to see that the input contains
# a '.'. This filters out whole numbers.
[ -z "${1##*.*}" ] &&
printf %f "$1" >/dev/null 2>&1
}
```
**Example Usage:**
```shell
$ is_float 1 && echo true
$
$ is_float 1.1 && echo true
$ true
```
## Check if a number is an integer
@ -914,10 +921,7 @@ is_float() {
```sh
is_int() {
# usage: is_int "number"
case $1 in
*[!-0-9]*|'') return 1 ;;
*[0-9]*)
esac
printf %d "$1" >/dev/null 2>&1
}
```