Humans hate pows and programmers hate humans - let's connect them! Background

The task is simple but every programmer has implemented it at least once. Stackoverflow has a lot of samples, but are they short enough to win?

Problem story

You're a grumpy programmer who was given the task of implementing file size input for the users. Since users don't use bytes everyone will just enter "1M", "1K", "3G", "3.14M" - but you need bytes! So you write a program to do the conversion.

Then your manager hands you dozens of user reports with complaints about weird large numbers in file size input. It seems you'll need to code the reverse conversion too.

What do you need to do?

Here's the trick: you should implement two-way conversion in single piece of code. Two separate functions used as needed? Nah, that's too simple - let's make one, short one!

For the purposes of this challenge, "kilobyte" means 1024 bytes, "megabyte" means 1024*1024 = 1048576 bytes, and "gigabyte" means 1024*1024*1024 = 1073741824 bytes.

Test data

Input   -&gt; Output  
5       -&gt; 5  
1023    -&gt; 1023  
1024    -&gt; 1K  
1K      -&gt; 1024  
1.5K    -&gt; 1536  
1536    -&gt; 1.5K  
1048576 -&gt; 1M  
1M      -&gt; 1048576  


Rules


Test value will not exceed 2*1024*1024*1024 or 2G
The following postfixes are used by users: K for kilobytes, M for megabytes, G for gigabytes
Code is not required to work with negative numbers
Do not use any external libraries (e.g. BCMath in PHP) besides bundled ones (e.g. math.h)
Standard loopholes are disallowed
Code should not produce anything on stderr
Your program can take input and produce output using [standard methods].(http://meta.codegolf.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
Python 2, 204 190 bytes
This is my first ever codegolf.
s=raw_input()
p=' KMG'
if s[-1]&lt;='9':
 e=0;r=int(s)
 while r&gt;=1024:r/=1024.0;e+=1
else:
 e=p.index(s[-1]);r=eval(s[:-1])
 while e&gt;0:r*=1024;e-=1
print(`r`if r%1!=0 else`int(r)`)+p[e].strip()