LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2015, 08:15 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 172

Rep: Reputation: 16
non numeric number to numeric


how can i change non numeric number to numeric?

for Example:
22.00 to 22
 
Old 06-17-2015, 08:21 AM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,651

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
I think you mean decimal to integer and it depends on the programming language you are using, please show what you have done and a bit more info.

Just seen your post tally, come on! After 157posts you should know better.

Last edited by Keith Hedger; 06-17-2015 at 08:22 AM. Reason: update
 
1 members found this post helpful.
Old 06-17-2015, 08:48 AM   #3
DoME69
Member
 
Registered: Jan 2008
Posts: 172

Original Poster
Rep: Reputation: 16
Sorry.

bash
 
Old 06-17-2015, 08:58 AM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,651

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
well BASH doesn't use decimals so I assume you are just using a string so just remove the decimal part like so:
Code:
keithhedger@LFSCerebro:~-> val=22.00
keithhedger@LFSCerebro:~-> echo ${val%.?*}
22
 
1 members found this post helpful.
Old 06-17-2015, 09:06 AM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,682

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by DoME69 View Post
how can i change non numeric number to numeric?

for Example:
22.00 to 22
Do you want to
(1) round to the nearest integer, or
(2) truncate (throw away the fractional part)?

Daniel B. Martin
 
Old 06-17-2015, 09:11 AM   #6
DoME69
Member
 
Registered: Jan 2008
Posts: 172

Original Poster
Rep: Reputation: 16
Thanks
 
Old 06-17-2015, 10:00 AM   #7
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,651

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
To round to nearest integer use
Code:
keithhedger@LFSCerebro:~-> echo "scale=0;(22.00+0.5)/1"|bc -l
22
keithhedger@LFSCerebro:~-> echo "scale=0;(22.5+0.5)/1"|bc -l
23
 
1 members found this post helpful.
Old 06-19-2015, 05:32 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.3
Posts: 17,548

Rep: Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423Reputation: 2423
Agree with danielbmartin; that was my first thought/qn too ..
 
Old 06-19-2015, 07:13 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Also: why th'hell use bash?!

The scripting-language built into bash is most-basic ... and really never intended to be used to do anything more than stringing a few commands together and poking at its command-line.

If you want to do "real" things, use a "real" scripting language: Perl, Ruby, PHP, Python ... the list goes on and on. All of them probably already-installed on your machine. Any of which you can access by placing #!shebang line at the top of your script-file.

The output of the command, when run, will not reveal what language-system is actually being used, and you will have the full power of that language ... doing the sort of things that that language was intended to do ... at your disposal.

Frankly, even if you 'somehow monkey-wrench' Bash into producing an acceptable result, you'll be creating or perpetuating "an un-maintainable sack of ... ." And there's plenty of that sort of thing on Planet Earth already! (And, BTW, I am intending that comment to have a purely technical, not personal, interpretation. "Given that you have the right tools for this job ready-at-hand, use the right tools for this job.")
 
  


Reply


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
[SOLVED] [Solved] spamassassin error: Argument perl_version isn't numeric in numeric ge (>=) carltm CentOS 12 12-02-2014 08:23 AM
[SOLVED] Numeric keypad not working nigelc Linux - Hardware 6 07-13-2011 01:26 AM
Help installing Numeric-23.6 Multra Linux - Newbie 3 10-26-2004 05:14 PM
chmod u+s = numeric? kidwired Linux - Newbie 4 01-19-2003 11:24 PM
Numeric Permissions MelLinux Linux - General 3 10-18-2002 01:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration