Problem in converting number in shell script

Hi All,

     I am writing a shell script in which I want to convert a number like :

Suppose the number is "98487657" and we have to convert it to "98000000", what I want to do is to retain first 2 digits and convert all remaining digits to "0".

Number could be of any length (length > 2).

Thanks in advance :slight_smile:

With awk:

echo '98487657' | awk '{printf("%d\n", substr($0,1,2) * 10^(length-2))}' 

Regards

Above command is working perfectly!!!

Thanks once again :slight_smile:

No need to call an external command. The following works for either bash or ksh93

$ NO=98487655
$ echo $NO
98487655
$ printf "%d\n" $((NO - ${NO:2}))
98000000

In any POSIX shell:

no=98487655
right=${no#??}
printf "%d%0${#right}d\n" "${no%"$right"}" 0