How about using string operations in from_epoch() to extract the nanoseconds:
$ perl -e ' my $e = "1297777805.12"; my ($int,$frac)=split(/\./,$e);
$frac=0+substr($frac."000000000",0,9); print "$frac\n"; '
120000000
$ perl -e ' my $e = "1297777805.00012"; my
($int,$frac)=split(/\./,$e); $frac=0+substr($frac."000000000",0,9);
print "$frac\n"; '
120000
2011/3/21 Michael R. Davis via RT <bug-DateTime@rt.cpan.org>:
Show quoted text> Sun Mar 20 20:33:42 2011: Request 66744 was acted upon.
> Transaction: Ticket created by MRDVT
> Queue: DateTime
> Subject: DateTime->strftime(%2N) Truncates not Rounds
> Broken in: 0.66
> Severity: Normal
> Owner: Nobody
> Requestors: MRDVT@cpan.org
> Status: new
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=66744 >
>
>
> I would think that we should be able to round trip 2 decimal places but
> this does not round trip because strftime truncates and does not round.
>
> Example that fails.
>
> $ perl -MDateTime -e 'print DateTime->from_epoch
> (epoch=>"1297777805.12")->strftime(q{%FT%T.%2N}), "\n";'
> 2011-02-15T13:50:05.11
>
> What I expect
>
> 2011-02-15T13:50:05.12
>
> The value is actually stored as
>
> 2011-02-15T13:50:05.119999885
>
> which is correct to 6 places. (I still would expect 9 places)
>
> I suggest changing _format_nanosecs so that we round not trunc.
>
> -return substr( $ret, 0, $precision );
> +return roundit($ret, $precision); #wrapper around Math::Round::nearest
> or something like it.
>
>