Well, something is to be said for approaching a problem from different points of view and uncovering new truths. So I'll give it a try.

The solution wasn't as smooth as I'd hope, apparently -0.0 == 0.

my $sign = ""; my $number = -0.000001; my $example = sprintf("%.5f", $number); #$example = $number; #uncomment this, to remove the initial rounding print "A. Started with : $example \n"; if ($example < 0) { $example = -$example; $sign = "-"; print "B. Less than zero: changed to $example \n"; } print "C. the number is $example \n"; if ($example == 0 ) { print "D1. the number ($example) is equal to zero, removing the si +gn.\n"; $example *= -1; #(couldn't hurt, it's zero) print "D2. the number ($example) is equal to zero, removing the si +gn.\n"; $sign = ''; } print "E. proceeding to sprint $example with sign $sign .\n"; $tret = sprintf("rounded float: %s%7.5f : unrounded %7.5f", $sign, $ex +ample, $number); print "$tret \n";
Output:
A. Started with : -0.00000 
C. the number is -0.00000 
D1. the number (-0.00000) is equal to zero, removing the sign.
D2. the number (0) is equal to zero, removing the sign.
E. proceeding to sprint 0 with sign  .
rounded float: 0.00000 : unrounded -0.00000 

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.