RotoValue:

Perhaps you can replace the sprintf function with a wrapped version. I've never replaced the core functions before, but I've seen references to it. Googling for perl replace core function came up with a couple useful looking links:

So perhaps you could do something like:

BEGIN{ *CORE::GLOBAL::old_sprintf = *CORE::GLOBAL::sprintf; *CORE::GLOBAL::sprintf = sub { my $formatted_string = old_sprintf(@_); # 0.###Z ==> .### $formatted_string =~ s/([^0-9])0(\.\d+)Z/$1$2/g; return old_sprintf(@_); } };

Which I adapted (probably incorrectly) from Corion's stack overflow post (the second link). I've never tried to override the core functions, but something like this might be a good solution for you. Of course, you may need to write some magic code to recognize the new format string, and figure out how to do the replacement(s) without messing up other replacements.

If you could do something cheesy like use a format like "blah blah %.fZ blah", and could rely on Z never being at the end of a number in your code, then you could do a replacement like the one I did above.

Update: Added "something like".

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^3: Can sprintf suppress leading zero for float < 1? by roboticus
in thread Can sprintf suppress leading zero for float < 1? by RotoValue

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.