good chemistry is complicated,and a little bit messy -LW PerlMonks

### Does perl have a round function? What about ceil() and floor()? Trig functions?

by faq_monk (Initiate)
 on Oct 08, 1999 at 00:20 UTC Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

Remember that `int()` merely truncates toward 0. For rounding to a certain number of digits, `sprintf()` or `printf()` is usually the easiest route.

```    printf("%.3f", 3.1415926535);       # prints 3.142
```

The POSIX module (part of the standard perl distribution) implements `ceil(),` `floor(),` and a number of other mathematical and trigonometric functions.

```    use POSIX;
\$ceil   = ceil(3.5);                        # 4
\$floor  = floor(3.5);                       # 3
```

In 5.000 to 5.003 Perls, trigonometry was done in the Math::Complex module. With 5.004, the Math::Trig module (part of the standard perl distribution) implements the trigonometric functions. Internally it uses the Math::Complex module and some functions can break out from the real axis into the complex plane, for example the inverse sine of 2.

Rounding in financial applications can have serious implications, and the rounding method used should be specified precisely. In these cases, it probably pays not to trust whichever system rounding is being used by Perl, but to instead implement the rounding function you need yourself.

Create A New User
Chatterbox?
 [Corion]: We-ird - I hadn't known this, but Ingress and Pokemon Go (both AR games in the real world where you run around) switched from using Google Maps to OpenStreetMaps, which is great. But I wonder why, as Ingress is (was?) owned by Google/Alphabet. But ... [Corion]: ... maybe not wholly owned, or the load on Google Maps was too high?! [choroba]: https://metacpan. org/author/ SIMBABQUE might know. He's a heavy Ingress player.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-03-19 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (236 votes). Check out past polls.

Notices?