JasonGenX
JasonGenX

Reputation: 5444

floating point accuracy with bash

I have:

DIFF=$(( ($END - $START) / 60 ))
echo "Build took $DIFF minutes" 

My output for 1:30 minutes is:

Build took 1 minutes

How do I employ floating point here so that my output will be:

Build took 1.50 minutes

Upvotes: 0

Views: 159

Answers (2)

Hai Vu
Hai Vu

Reputation: 40773

I don't think bash supports floating point. You can use the bc command instead:

DIFF=$(bc <<< "scale=2; ($END - $START) / 60")
echo "Build took $DIFF minutes" 

Upvotes: 1

Kent
Kent

Reputation: 195219

use bc to get precision

example:

kent$  echo "scale=2;(190-100)/60"|bc
1.50

replace hardcoded number with your variables.

Upvotes: 3

Related Questions