LinuxQuestions.org
Help answer threads with 0 replies.
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, 11:06 AM   #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, 11:19 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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, 11:30 AM   #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, 11:38 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

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

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
There's no conversion involved here, there is division involved here, and yes awk can do basic math.
 
Old 03-22-2014, 10: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, 12:37 AM   #7
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

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, 01: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, 05:28 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

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

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

All times are GMT -5. The time now is 10:18 PM.

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