On 2018-07-07 18:54, Per Jessen wrote:
Anton Aylward wrote:
On 07/07/18 08:50 AM, Carlos E. R. wrote:
Do we have something that would round a number in a script?
In a Ruby script there is the numeric function 'floor()' that does all of what you describe. I see that it is also available in the POSIX compatibility module for Perl. There is a similar function in Python.
The bash shell doesn't, it seems, do floating point arithmetic. of course the older ksh does
---
for i in 72.0009 86.0044 96.01 240.005 do ksh93 -c "print $(( floor($i) ))" done
----
OOPS! have to start that in ksh93 anyway as bash upchuks on things like "72.0009".
It works fine here:
for i in 72.0009 86.0044 96.01 240.005 do printf "%.0f\n" $i done
72 86 96 240
Only if your locale uses the decimal point. Spain uses the comma as decimal separator, so it doesn't. -- Cheers / Saludos, Carlos E. R. (from 42.3 x86_64 "Malachite" at Telcontar)