in reply to Re: Negative zero? There's gotta be a sprintf that undoes that, right?
in thread Negative zero? There's gotta be a sprintf that undoes that, right?

Now... here's a really sick method that uses the regexp, but only to remove the leading - when needed. -0 == 0 but also -0 lt 0 so...
$num=sprintf("%7.5f",$num); $num=~s/^-// if $num == 0 && $num lt 0;
minimal regexp work and works for any precision.

Update Caveat... only works in locales where "-" is lower than 0-9

                - Ant
                - Some of my best work - (1 2 3)

  • Comment on Re^2: Negative zero? There's gotta be a sprintf that undoes that, right?
  • Download Code