Re: printf: zero pad after the decimal a given amount



jidanni@xxxxxxxxxxx wrote:
Why is there no way to tell printf to zero pad like the right column:

One reason is that what you want is ill-defined. If we are going to tweak
sprintf to make it suit our personal preferences, I'd rather see a
conversion character that behaved just like %f if given a good number, but
returned the empty string if given either an empty string or undef (rather
than converting it to zero and then applying %f to the zero.)

0.1 :0.100
0.05 :0.050
0.03 :0.030
0.025 :0.025
0.02 :0.020
0.015 :0.015

Apparently you want to preserve non-zero digits even if that means going
beyond 3 digits right of the decimal. But why did you stop at 4?

0.014999999999999999444888

0.0125 :0.0125


0.0125000000000000006938893

How many consecutive zeros or nines are needed before you decide there are
enough to ignore what is the right of them?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.



Relevant Pages

  • Re: printf: zero pad after the decimal a given amount
    ... returned the empty string if given either an empty string or undef (rather ... than converting it to zero and then applying %f to the zero.) ... Apparently you want to preserve non-zero digits even if that means going ... is using 64-bit long doubles you will need 4932 instead. ...
    (comp.lang.perl.misc)
  • Re: Coerce Null to Zero?
    ... Is there a similar technique for coercing it to Zero with numeric fields? ... lRes = Val) ... I prefer an empty string to zero as a default value, ...
    (microsoft.public.vb.syntax)
  • Re: Coerce Null to Zero?
    ... IOW, just consider the field at its ... lRes = Val) ... I prefer an empty string to zero as a default value, ...
    (microsoft.public.vb.syntax)
  • RE: How does defined work?
    ... Both Zero "0" and empty string " " are defined values in Perl, ... ||I am posting this query in beginners instead of beginners-cgi because I ... ||How can I make this execute the die statement when userId is missing from ...
    (perl.beginners)
  • Re: Validation Rule
    ... I have checked the fields required porperty to yes and allow zero length ... anyway and I select no and get an action failed dialogue message. ... prevents empty string values from being saved. ...
    (microsoft.public.access.formscoding)