From a8f03f5ddd01c8f3e42f6f4b527912a39b20eeb9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 20 Sep 2019 15:42:00 +0300 Subject: docs: update --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index f619ad3..539728a 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ See something incorrectly described, buggy or outright wrong? Open an issue or s * [Miscellaneous](#miscellaneous) * [ARITHMETIC](#arithmetic-1) * [Ternary Tests](#ternary-tests) + * [Check if a number is a float](#check-if-a-number-is-a-float) * [TRAPS](#traps) * [Do something on script exit](#do-something-on-script-exit) * [Ignore terminal interrupt (CTRL+C, SIGINT)](#ignore-terminal-interrupt-ctrlc-sigint) @@ -802,6 +803,32 @@ For use in `[ ]` `if [ ]; then` and `test`. var=$((var2 > var ? var2 : var)) ``` +## Check if a number is a float + +**Example Function:** + +```sh +is_float() { + # Usage: is_float "number" + case $1 in + *.*.*|*[!-.0-9]*) ;; + *[0-9].[0-9]*) return 0 + esac + + return 1 +} +``` + +**Example Usage:** + +```shell +$ is_float 1.1 && echo true +true + +$ is_float 1 && echo true +$ +``` + # TRAPS Traps allow a script to execute code on various signals. In [pxltrm](https://github.com/dylanaraps/pxltrm) (*a pixel art editor written in bash*) traps are used to redraw the user interface on window resize. Another use case is cleaning up temporary files on script exit. -- cgit v1.2.3