Skip to content

Instantly share code, notes, and snippets.

@stalluri
Last active March 11, 2016 18:23
Show Gist options
  • Save stalluri/df5385f63c4090ce0c59 to your computer and use it in GitHub Desktop.
Save stalluri/df5385f63c4090ce0c59 to your computer and use it in GitHub Desktop.
Shell float to integer conversion and integer arithmetic
# 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