Angelo Ulivieri
Angelo Ulivieri

Reputation: 23

How can I round an evalue in Perl?

I have an evalue number like: 3,49489484848484E-23 and want to round it to 3,48E-23

How can I do it? I can't found any Perl functions that do this rounding.

Upvotes: 2

Views: 275

Answers (2)

librarian
librarian

Reputation: 129

Perl doesn't have a round() function. Treating floats is always system-dependent, etc. From the Perl FAQ I can offer you this:

For rounding to a certain number of digits, sprintf() or printf() is usually the easiest route.

[...]

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 of rounding is being used by Perl, but instead to implement the rounding function you need yourself.

Upvotes: 6

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

You can use sprintf or printf:

printf '%.2e', 3.49489484848484E-23; # prints 3.49e-23

See also the Perl FAQ.

Upvotes: 10

Related Questions