Last active
August 29, 2015 14:11
-
-
Save nikAizuddin/0712304e15d58556d343 to your computer and use it in GitHub Desktop.
How to compare float numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#===================================================================== | |
# FILE: compare_float.sh | |
# | |
# USAGE: bash compare_float.sh | |
# | |
# DESCRIPTION: This script shows how to compare float numbers. | |
# | |
# REQUIREMENTS: --- | |
# BUGS: --- | |
# NOTES: --- | |
# AUTHOR: Nik Mohamad Aizuddin bin Nik Azmi | |
# EMAIL: [email protected] | |
# VERSION: 1.0 | |
# CREATED: 12/DECEMBER/2014, 21:09 | |
# REVISION: --- | |
#===================================================================== | |
#--------------------------------------------------------------------- | |
# Get input from user | |
#--------------------------------------------------------------------- | |
echo -n "Please insert number_1 (for example 3.125): " | |
read number_1 | |
echo -n "Please insert number_2 (for example 6.129): " | |
read number_2 | |
#--------------------------------------------------------------------- | |
# Compare number_1 and number_2 | |
#--------------------------------------------------------------------- | |
is_less_than=`echo "$number_1 < $number_2" | bc -l` | |
is_equal=`echo "$number_1 == $number_2" | bc -l` | |
is_more_than=`echo "$number_1 > $number_2" | bc -l` | |
#--------------------------------------------------------------------- | |
# Print results | |
#--------------------------------------------------------------------- | |
if [[ $is_less_than -eq 1 ]]; then | |
echo "number_1 is less than number_2" | |
fi | |
if [[ $is_equal -eq 1 ]]; then | |
echo "number_1 is equal to number_2" | |
fi | |
if [[ $is_more_than -eq 1 ]]; then | |
echo "number_1 is more than number_2" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment