K
K
ksvdon2014-10-22 22:29:40
bash
ksvdon, 2014-10-22 22:29:40

How to cut off zeros in a number?

I need to check the same data from different sources. The output in each looks a little different. For example: in one case, after the decimal point there are numbers (6 pieces) 27.970000, and in the other case, the entry is 27.97; How to remove extra zeros (I take a variable with extra zeros from a file)?
I made up something like this

p=27.978440
echo "$p"
p=$(echo "$p" | cut -d . -f 2 )
tmpp=`echo "$p" | grep 0`
while [ -n "$tmpp" ];do
p=${p%$*0}
tmpp=`echo "$p" | grep [0]`
done

an endless cycle is obtained. I need to check the last digit of the number "0 is not 0". I can't figure out how? The template doesn't fit. Need better idea than "grep[0]"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Lerg, 2014-10-22
@Lerg

Converting to number and comparing between numbers not working?
In general, as soon as the script starts to get complicated, I switch to Python or Lua.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question