2021-04-09 15:25:51 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-04-09 15:34:26 -05:00
|
|
|
# Returns a passed number as comma-separated e.g. pass $1 = 80000000000 and receive 80,000,000,000
|
2021-04-09 15:25:51 -05:00
|
|
|
# REF: https://unix.stackexchange.com/questions/113795/add-thousands-separator-in-a-number
|
|
|
|
|
|
|
|
function commanum () {
|
|
|
|
LC_NUMERIC=en_US printf "%'.f" $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# test for interactive shell / OK to echo text
|
|
|
|
#[ $(echo $- |grep i |wc -l) -gt 0 ] &&
|
|
|
|
[ ! "$1" = "" ] && commanum $1
|
2021-04-09 15:34:26 -05:00
|
|
|
|
|
|
|
# Example usage:
|
|
|
|
#$ tmpvar=$(./commasep-num.mrg 80000000000)
|
|
|
|
#$ echo $tmpvar
|
|
|
|
#80,000,000,000
|
|
|
|
# Limitation: it doesn't handle fractional numbers x.xx , just integers - anything after the decimal gets dropped
|