Last active
March 11, 2016 18:23
-
-
Save stalluri/df5385f63c4090ce0c59 to your computer and use it in GitHub Desktop.
Shell float to integer conversion and integer arithmetic
This file contains 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
# Start with a float number | |
NP_TRIGGER_VALUES=999.23 | |
# Convert float to integer value as shell supports only integer arithmetic not float | |
CURRENT_QUEUE_COUNT=$(printf "%.0f" $NP_TRIGGER_VALUES ) | |
# Integer value | |
DYNO_CAPACITY=500 | |
# Division; Give a space before and after the operator - shell gotcha | |
REQUIRED_DYNO_COUNT=`expr $CURRENT_QUEUE_COUNT / $DYNO | |
# Shell by default rounds down. So for roundup, manually add +1 | |
REQUIRED_DYNO_COUNT=`expr $REQUIRED_DYNO_COUNT + 1` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment