Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-21-2004, 06:52 PM   #1
LQ Newbie
Registered: Sep 2004
Location: Australia
Posts: 7

Rep: Reputation: 0
Unhappy managing floating point


i was just wondering if their si a way to manage floating point . Say for example,

If I do something like this... TOTAL = `expr 125 "/" 100`.. would give me 1 not 1.25 as expected.. any idea of how to manage this..

Old 09-21-2004, 09:02 PM   #2
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
I don't think you can do floating point in the shell, but if you have bc installed, you can do this:

TOTAL=`echo "scale=3;125/100" | bc /dev/stdin`

Scale defines how many figures after the decimal point. This is also possible with dc:

TOTAL=`echo "3 k 125 100 / p" | dc /dev/stdin`
Old 09-21-2004, 09:05 PM   #3
LQ Newbie
Registered: Sep 2004
Location: Australia
Posts: 7

Original Poster
Rep: Reputation: 0
Excellent cromagnon.. it works beautiful



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating Point in kernel 2.4.28 lucs Slackware 1 10-19-2005 08:33 AM
Floating point exception hemk76 Linux - Software 1 05-06-2005 11:49 PM
floating point multiplication irfanhab Programming 0 12-23-2004 10:13 PM
modulo of 2 floating point numbers? jenna_h Programming 6 09-24-2004 09:39 AM
floating point numbers in java spyghost Programming 8 09-06-2003 06:21 PM > Forums > Linux Forums > Linux - General

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

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