Printf statement

The printf statement

pay_amount=$(printf "%013.3f" "$4")

working perfectly at one path(xxx/home/rsh) and showing error (printf: 216.000: invalid number) at another path(/opt/xxxx/xxxx).
what will be the reason?

thanks in advance

$4 is not numeric, or is null

$4 is floating values like 216.00, 1984.00 etc

When printf encounters a character that is not [:digit:] or a dot or a - you get that error. Nothing else does that. The data is the problem, not necessarily the code.

It can be an unprintable character. try

echo $4 | od

And you are positive that the 000 characters are not character O rather than numeric 0

Perhaps it is your locale?

$ printf "%013.3f\n" 3.14
000000003.140
$ LC_NUMERIC=en_DK.utf8
$ printf "%013.3f\n" 3.14
-bash: printf: 3.14: invalid number
000000000,000
$ printf "%013.3f\n" 3,14
000000003,140