LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2011, 01:20 PM   #1
alirz
LQ Newbie
 
Registered: Jun 2011
Posts: 19

Rep: Reputation: Disabled
how to get decimal value


Hi,

ok so i have a small script that takes the time in seconds(this is a very long number like 615.232145457577) and i convert it to minutes or hours by dividing by 60 or 3600 respectively.

I would like to be able to get the result with maybe upto to 2 decimal values.

If i do echo "613.568787987975 / 3600" |bc -l
this gives: .17043577444110416666

How can i just get .17

Thanks
 
Old 07-04-2011, 01:23 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Code:
echo -e "scale=2\n613.568787987975 / 3600" |bc -l
 
Old 07-04-2011, 01:24 PM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You don't need the newline. A semi-colon will do:

echo "scale=2; division" | bc -l
 
Old 07-04-2011, 01:26 PM   #4
alirz
LQ Newbie
 
Registered: Jun 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
cool, thanks both of you . it works.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ANSI C decimal to octal SpLaSh212 Programming 14 03-07-2009 02:33 PM
Decimal separator morfeus80 Linux - Newbie 2 04-21-2008 04:32 AM
Decimal to binary conversion master General 10 12-21-2007 02:03 AM
Math with 2 decimal places newbie_adm Linux - Newbie 1 09-15-2006 12:14 AM
Decimal to binary maldini1010 Programming 6 02-01-2005 04:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration