pstadler / ticker.sh

Real-time stock tickers from the command-line.
MIT License
511 stars 87 forks source link

problem with floating point conversion #23

Closed yadaniel closed 3 years ago

yadaniel commented 4 years ago

floating point conversion with printf seems to blow up when there are trailing spaces in variables I added 3 lines to the script and it works fine now. Thank you for the script.

else nonRegularMarketSign='' price=$(query $symbol 'regularMarketPrice') diff=$(query $symbol 'regularMarketChange') percent=$(query $symbol 'regularMarketChangePercent') fi

yadaniel commented 4 years ago

carrige return seems to be attached to variables somehow space seems to work in the script but not on command line

price=${price%%'\r'} diff=${diff%%'\r'} percent=${percent%%'\r'}

pstadler commented 4 years ago

Which operating system / shell are you using?

yadaniel commented 4 years ago

I am using cygwin and my shell is bash $ echo $BASH_VERSION 4.4.12(3)-release

Here is the output.

$ ./ticker.sh MSFT : Ungültige Zahl.ile 81: printf: 213.98 MSFT 0.00

81 is the line with printf "%-10s$COLOR_BOLD%8.2f$COLOR_RESET" $symbol $price 213.98 comes from price

when I add debug option set -x

So, '\r' probably gets fetched from request and gets even interpreted by printf. Don't know why '$' appears in '[' $'213.98\r' '!=' null ']'

price=${price%%[[:space:]]} Somehow [[:space:]] works in script robust

price=${price%%'\r'} Somehow this does not work in script any more :)

I am just a bash user, possible that I have mixed something up.

pstadler commented 4 years ago

Please try to change LC_NUMERIC and LANG to en_US.UTF-8 here and let me know whether this solves the problem.