[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Testing numeric data
From: |
hancooper |
Subject: |
Testing numeric data |
Date: |
Mon, 23 Aug 2021 00:02:31 +0000 |
I have the following code that determines if a number in numeric.
But when I use
frmt="flp" and `$1` set to `5.3`.
`k` is still `0`
# floating point numbers in fixed-point format
local flp='^[-+]?[0-9]*[.,]?[0-9]+$'
local pvflp='^+?[0-9]*[.,]?[0-9]+$'
local ngflp='^-[0-9]*[.,]?[0-9]+$'
# floating point numbers in exponential format
local flpe='^[-+]?[0-9]*[.,]?[0-9]+(?:[eE][-+]?[0-9]+)?$'
local pvflpe='^+?[0-9]*[.,]?[0-9]+(?:[eE][-+]?[0-9]+)?$'
local ngflpe='^-[0-9]*[.,]?[0-9]+(?:[eE][-+]?[0-9]+)?$'
declare -i k=0
case $frmt in
("flp") [[ "$1" =~ "$flp" ]] && k=1 ;;
("pvflp") [[ "$1" =~ "$pvflp" ]] && k=1 ;;
("ngflp") [[ "$1" =~ "$ngflp" ]] && k=1 ;;
("flpe") [[ "$1" =~ "$flpe" ]] && k=1 ;;
("pvflpe") [[ "$1" =~ "$pvflpe" ]] && k=1 ;;
("ngflpe") [[ "$1" =~ "$ngflpe" ]] && k=1 ;;
(*) [[ "$1" =~ "$flp" ]] && k=1 ;;
esac
echo "$k"
- Testing numeric data,
hancooper <=