Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-04-2013, 01:14 PM   #1
Registered: Dec 2013
Posts: 113

Rep: Reputation: Disabled
Floating number in linux cell script

---How can I represent floating number in linux cell scripting---
I am working in bash cell

echo "Enter basic salary:"
read basic
echo "HRA `expr 0.2 \* $basic`"

Output shows:
non-numeric arguments.

<< HELP >>
Old 12-04-2013, 01:30 PM   #2
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132Reputation: 2132
Do you mean "shell"? There's no such thing as Linux cell scripting or the bash cell.

The shell can't operate on non-intergers, you'll need to pass it to something that can, such as bc:
echo "0.2 * $basic" | bc -l
Old 12-04-2013, 11:36 PM   #3
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 331

Rep: Reputation: 60
You can also use GNU Octave. Have a look at this tutorial.

As an example, here is a script to convert a Xorg modeline into a framebuffer mode:
#!/usr/bin/octave -q
bpp = 16;
DCF = sscanf(argv(){1}, "%f");
HR  = sscanf(argv(){2}, "%f");
SH1 = sscanf(argv(){3}, "%f");
SH2 = sscanf(argv(){4}, "%f");
HFL = sscanf(argv(){5}, "%f");
VR  = sscanf(argv(){6}, "%f");
SV1 = sscanf(argv(){7}, "%f");
SV2 = sscanf(argv(){8}, "%f"); 
VFL = sscanf(argv(){9}, "%f");
pixclock = 1000000 / DCF;
left_margin = HFL - SH2;
right_margin = SH1 - HR;
hsync_len = SH2 - SH1;

# 3) vertical timings:
upper_margin = VFL - SV2;
lower_margin = SV1 - VR;
vsync_len = SV2 - SV1;

RR = DCF / (HFL * VFL) *1e6;
HSF = DCF / HFL * 1e3;

printf("mode \"%dx%d\"\n",HR,VR);
printf("   # D: %3.2f MHz, H: %3.2f kHz, V: %2.2f Hz\n", DCF, HSF, RR);
printf("   geometry %d %d %d %d %d\n", HR, VR, HR, VR, bpp);
printf("   timings %d %d %d %d %d %d %d\n", ...
                                 pixclock, left_margin, right_margin, ...
                                 upper_margin, lower_margin, ...
                                 hsync_len, vsync_len);


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 34 10-12-2016 09:09 AM
[SOLVED] absoulte value of a floating number nesrin Programming 2 01-11-2011 04:07 AM
How to do arithmatic operation on floating number by using expr ??? raman.kumar Linux - Newbie 2 05-18-2009 08:02 AM
floating point number vijraj Programming 2 03-07-2007 05:17 PM
floating point number division vijraj Programming 9 03-06-2007 11:36 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:53 PM.

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