-1

The following is an example of a mysql return column. select bandwidth from aTable

445355099

986654

7521

....

How can I modify to show in Mega, kilo and G?

424M

963k

7.3k

Thanks

Ming Leung
  • 385
  • 2
  • 13
  • 1
    Welcome to StackOverflow. We are not a code generation service. Please show what you've tried and/or researched thus far so we can point you in the right direction. – dg99 Jun 13 '14 at 21:10

1 Answers1

1

Take a returned result, and:

  • If it's greater than 1073741824 (1024 cubed), divide it by this number 1073741824 and round the result, then append G;
  • If it's greater than 1048576 (1024 squared), divide by 1048576, round the result and append M;
  • If it's greater then 1024, divide it by 1024, round the result and append k;
  • Otherwise return as is, probably appending bytes.
Andre Polykanine
  • 3,291
  • 18
  • 28