Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I will get value like 2743410360.320 and I want value like 2743410360 to a variable.

I tried

INTValueOfGB=$ echo "($gb+0.5)/1" | bc

But I am getting (standard_in) 1: syntax error

share|improve this question
Please check that your code's syntax is still the one you intended to post after I edited it. (That solitary $ sign looks quite interesting.) –  manatwork Nov 15 '13 at 11:23

2 Answers 2

You can use printf for rounding:

$ printf "%.0f" 2743410360.320
share|improve this answer
In bash 4.1 the builtin printf says “invalid number”. Works fine with /usr/bin/printf. –  manatwork Nov 15 '13 at 11:39
@manatwork Works for me with bash 4.1.5 on Debian squeeze and even bash 3.2.39 on Ubuntu 8.04. –  Gilles Nov 16 '13 at 22:18
Indeed. Works fine in bash 4.2. Or maybe the problem was not the version – the first try was on Cygwin. –  manatwork Nov 17 '13 at 12:36
I tried it is not working fine when i am passing a value $ printf "%.0f" $gb –  vin Nov 18 '13 at 5:58
@manatwork: Are you using %i or %.0f? The former says 'invalid number' for me, the latter works. –  Flimzy Mar 6 at 15:14
$ p=2743410360.320
$ echo $p
$ echo ${p%%.*}
share|improve this answer
The +0.5 in the original code looks like rounding is needed. –  manatwork Nov 15 '13 at 11:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.