Converting string to negative decimal value

I need code for converting a string to a negative decimal value.
For ex, i have the value in the form of a string (5489.95-) i need to convert it into decimal value (-5489.95) while getting output using printf command.

i know how to get as a string
a="5489.95-"
printf "%10s"$a >>xyz.dat

need as a decimal value

a="-${a%?}"

Hi,
Actually the string value is obtained from another file.It can be either a postive number or a negative number in the form of a string.
If it is a psotive(547665.98) get a positive decimal value itself( 547665.98), but if it is a negative(547665.98-) get it as a negative decimal value (-547665.98).

Thanks

if [ `echo $a | grep "\-$"` ]; then a="-${a%?}"; fi
1 Like

Thanks a lot!! It works fine.

Without externals commands (faster):

case $a in (*-) a=-${a%?}; esac

or in bash/ksh93:

a=${a/*-/-${a%?}}