in reply to String numerifier with SI prefix support

Interesting. I have a script which perfoms essentially the inverse operation. Given a floating-point numerical input, I produce an output string formatted in engineering notation. For example:
0.000456 --> 456u
My script has fewer bells and whistles, and I hadn't even considered the [yYzZ] ranges :)

Replies are listed 'Best First'.
Re^2: String numerifier with SI prefix support
by repellent (Priest) on Feb 01, 2008 at 02:18 UTC
    Hello from JAHW engineer :) So,

        yourfunc(0.00000456) => "4.56u" or "456e-2u" ?
      My function "autoscales", so it would output "4.56u". But, I could see the value in having a mode where it could fix the scale to always output "u", or whatever the user specifies. Here is a sample of what my function does (left column is input, right is output):
      1234 --> 1.23k 50000 --> 50k 5000 --> 5k 500 --> 500 0.012 --> 12m 0.00055555 --> 555u 5e-5 --> 50u 5E-5 --> 50u 5.0e-05 --> 50u -193.7 --> -193 -5 --> -5 -0.7895 --> -789m 555555555555555555 --> 5.56e+17 0.000000000000000777 --> 7.77e-16 9876543 --> 9.87M

      Obviously, this is only used for very coarse estimates. It does not handle rounding or precision correctly.