最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell腳本nicenumber實現(xiàn)代碼

 更新時間:2016年08月14日 11:18:26   投稿:mdxy-dxy  
給出一個數(shù)字,用逗號分隔的形式顯示出來,希望DD和TD被實例化等

Given a number, shows it in comma-separated form.Expects DD and TD to be instantiated. Instantiates nicenum. or, if a second arg is specified, the output is echoed to stdout.

廢話不多說,首先是

#!/bin/sh
# nicenumber -- Given a number, shows it in comma-separated form.
# Expects DD and TD to be instantiated. Instantiates nicenum
# or, if a second arg is specified, the output is echoed to stdout.

nicenumber()
{
 # Note that we assume that '.' is the decimal separator in
 # the INPUT value to this script. The decimal separator in the output value is
 # '.' unless specified by the user with the -d flag

 integer=$(echo $1 | cut -d. -f1)       # left of the decimal
 decimal=$(echo $1 | cut -d. -f2)       # right of the decimal

 if [ $decimal != $1 ]; then
  # There's a fractional part, so let's include it.
  result="${DD:="."}$decimal"
 fi

 thousands=$integer

 while [ $thousands -gt 999 ]; do
  remainder=$(($thousands % 1000))  # three least significant digits

  while [ ${#remainder} -lt 3 ] ; do # force leading zeros as needed
   remainder="0$remainder"
  done

  thousands=$(($thousands / 1000))  # to left of remainder, if any
  result="${TD:=","}${remainder}${result}"  # builds right to left
 done

 nicenum="${thousands}${result}"
 if [ ! -z $2 ] ; then
  echo $nicenum
 fi
}

DD="." # decimal point delimiter, to separate integer and fractional values
TD="," # thousands delimiter, to separate every three digits

while getopts "d:t:" opt; do
 case $opt in
  d ) DD="$OPTARG"  ;;
  t ) TD="$OPTARG"  ;;
 esac
done
shift $(($OPTIND - 1))

if [ $# -eq 0 ] ; then
 echo "Usage: $(basename $0) [-d c] [-t c] numeric value"
 echo " -d specifies the decimal point delimiter (default '.')"
 echo " -t specifies the thousands delimiter (default ',')"
 exit 0
fi

nicenumber $1 1     # second arg forces nicenumber to 'echo' output

exit 0

這腳本我們以后分析,現(xiàn)在先mark下。

相關文章

最新評論

缙云县| 新沂市| 河北区| 隆安县| 五家渠市| 峨眉山市| 隆子县| 铜川市| 呼图壁县| 库尔勒市| 福泉市| 锦屏县| 定安县| 布拖县| 瑞昌市| 博客| 武山县| 宜兰县| 波密县| 武穴市| 永安市| 汉阴县| 昭觉县| 山阴县| 象州县| 兴隆县| 都江堰市| 九龙坡区| 瓦房店市| 砚山县| 牡丹江市| 盐津县| 长白| 武城县| 宜丰县| 台南县| 章丘市| 唐海县| 肇东市| 兴仁县| 商南县|