aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2019-09-24 08:25:03 +0300
committerDylan Araps <dylan.araps@gmail.com>2019-09-24 08:25:03 +0300
commit48eb245a27f2b1974cff1b1083a00cf1795644f5 (patch)
tree08d7b0f3a5d4f1cafebe318376d53249dcf2ed1b
parentdc6de0ef34bcfad6e7673b7e3c5aef58d33ce734 (diff)
downloadpure-sh-bible-48eb245a27f2b1974cff1b1083a00cf1795644f5.tar.gz
pure-sh-bible-48eb245a27f2b1974cff1b1083a00cf1795644f5.zip
docs: update
-rw-r--r--README.md26
1 files changed, 15 insertions, 11 deletions
diff --git a/README.md b/README.md
index 4e9d6c5..b6a57de 100644
--- a/README.md
+++ b/README.md
@@ -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
}
```