Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:46:11+00:00 2026-06-17T20:46:11+00:00

Strange I can’t find an answer on this (probably not searching correctly). I want

  • 0

Strange I can’t find an answer on this (probably not searching correctly).

I want to remove all numbers after the first instance of a non-zero number.

For example if I have 0.00208239, how can I reduce it down to 0.002, better yet 2m (SI units)? This data comes from MySQL but routes through PHP AJAX into an id’d div.

Note The first significant digit can be anywhere, from 10^-6 to 10^6. So, 1,000.77 needs to be 1,000, or if you’re awesome, 1k.

I’m lamping it with jQuery, so best answer of js, jQuery, MySQL, PHP gets check, but any valid solution of course gets +.

Many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:46:13+00:00Added an answer on June 17, 2026 at 8:46 pm

    You could use a regex to get the first number, then use a lookup table to add the suffix:

    $suffixes = array( 
        -6 => 'µ',
        -5 => '',
        -4 => '',
        -3 => 'm',
        -2 => 'c',
        -1 => '',
         0 => '',
         1 => '',
         2 => '',
         3 => 'k',
         4 => '',
         5 => '',
         6 => 'M',
    );
    
    preg_match( '/^[^1-9]*([1-9])/', $str, $matches);
    $ten = floor( log( $str, 10));
    echo $matches[1] . $suffixes[ $ten ] . "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems strange I can't find an answer to this, but here goes: This: foreach
Strange, but I can't find a duplicate for this question. I have a superclass
I think it's strange that I can't find anything on this, but that's the
I'm getting a strange warning I can't fix with Symfony2 version v2.0.12. This was
I can't remember exactly where I've seen this strange `1 (single-tick and the number
I can't find any evidence online of pthread_cond_wait being strange on Mac OS X,
This is very strange and I can't get my head around what is causing
I'm finding it strange that I can't find any information about how to populate
It seems really strange and I can't figure out why this is happening. This
I know this sounds strange but I can't get it. Here (http://pytest.org/dev/getting-started.html) it says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.