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!
You could use a regex to get the first number, then use a lookup table to add the suffix: