Newsgroups: comp.lang.perl.misc
From: PerlFAQ Server <br...@stonehenge.com>
Date: Sat, 10 May 2008 06:03:04 -0700
Local: Sat, May 10 2008 9:03 am
Subject: FAQ 4.4 Does Perl have a round() function? What about ceil() and floor()? Trig functions?
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.4: Does Perl have a round() function? What about ceil() and floor()? Trig functions? Remember that "int()" merely truncates toward 0. For rounding to a printf("%.3f", 3.1415926535); # prints 3.142 The "POSIX" module (part of the standard Perl distribution) implements use POSIX; In 5.000 to 5.003 perls, trigonometry was done in the "Math::Complex" Rounding in financial applications can have serious implications, and To see why, notice how you'll still have an issue on half-way-point for ($i = 0; $i < 1.01; $i += 0.05) { printf "%.1f ",$i} 0.0 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.4 0.4 0.5 0.5 0.6 0.7 0.7 Don't blame Perl. It's the same as in C. IEEE says we have to do this. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They If you'd like to help maintain the perlfaq, see the details in You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||