LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-22-2014, 12:06 PM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
convert a number into millions


Hi,

can we convert any number like 768565746354646 to millions using awk?

or is there any link for such type of conversions so that i'll study it.
 
Old 03-22-2014, 12:19 PM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
I'm not sure what you mean by "converting ... to millions". Do you mean 768565746.354646 millions or 768565746.354646 X 10^6? Please show us what kind of output you want.
jdk
 
Old 03-22-2014, 12:30 PM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jdkaye View Post
I'm not sure what you mean by "converting ... to millions". Do you mean 768565746.354646 millions or 768565746.354646 X 10^6? Please show us what kind of output you want.
jdk
would like to have output like 768565746.354646 M
 
Old 03-22-2014, 12:38 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
So what have you tried with awk and where are you stuck?
 
Old 03-22-2014, 08:47 PM   #5
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
There's no conversion involved here, there is division involved here, and yes awk can do basic math.
 
Old 03-22-2014, 11:35 PM   #6
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
So what have you tried with awk and where are you stuck?
i tried this:

x=87654987
echo $x|awk '{ printf "%.4f M\n", $1 / 1000000 }'

output:
87.6550 M

is this correct way to show values in millions?
 
Old 03-23-2014, 01:37 AM   #7
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Quote:
Originally Posted by santosh0782 View Post
i tried this:

x=87654987
echo $x|awk '{ printf "%.4f M\n", $1 / 1000000 }'

output:
87.6550 M

is this correct way to show values in millions?
That's one way. There are many ways to show values in millions. This is one of them. I don't know what you mean by "correct way".
jdk
 
1 members found this post helpful.
Old 03-23-2014, 02:31 AM   #8
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jdkaye View Post
That's one way. There are many ways to show values in millions. This is one of them. I don't know what you mean by "correct way".
jdk
ok. Thanks a lot :-)
 
Old 03-23-2014, 06:28 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
I agree with jdk. Ultimately the question is back to you, ie does that answer look like what you want or not?

If it does and you have a solution, please mark as SOLVED.
 
1 members found this post helpful.
  


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
convert number (not hex) into Decimal number drManhattan Programming 10 10-15-2011 09:53 PM
[SOLVED] Convert string to number without 0 in the beginning nadinnne Linux - Newbie 11 06-08-2010 09:27 AM
Convert a variable number in megabytes ibizatunes Programming 8 02-25-2010 03:08 AM
convert string into number, shell mystical dervish Programming 9 08-13-2007 04:32 AM
kernel cannot convert a name into device number dreambrother Linux - Newbie 4 05-31-2005 06:51 PM


All times are GMT -5. The time now is 08:29 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