Getting a variable from printf
I had to do some rounding in a script using printf, but how do I get the output to become a variable
Code:
$velper=141.600 (I have a feeling this is really simple) thanks |
Code:
myvar="$(command)" |
@ Reply
Hi mp85,
Welcome to LQ!!! If you are trying to round of the value of variable velper and want to replace the existing value of velper to the rounded of value then you can do it as follows: Code:
velper=`printf "%.0f\n" $velper` Code:
new=`printf "%.0f\n" $velper` |
Assuming this is bash:
Code:
newVariable=$(printf "%.0f\n" $velper) |
Quote:
|
Or alternately, still assuming bash:
Code:
$ velper=141.600 And remember, always quote your variable substitutions. Get into the habit now. |
All times are GMT -5. The time now is 10:37 PM. |