Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Answer: How do I round a number?

by powerman (Friar)
on Apr 23, 2002 at 11:44 UTC ( #161255=categorized answer: print w/replies, xml ) Need Help??

Q&A > math > How do I round a number? - Answer contributed by powerman

Here shown all round-like functions which exists in perl:
#!/usr/bin/perl use POSIX; @a=(3.3, 3.5, 3.7, -3.3, -3.5, -3.7, 3.45); print "number\tint\tprintf\tfloor\tceil\n"; printf "%.2f\t%.1f\t%.1f\t%.2f\t%.2f\n", $_, int, $_, floor($_), ceil($_) foreach (@a);
This code produce this output:
number	int	printf	floor	ceil
3.30	3.0	3.3	3.00	4.00
3.50	3.0	3.5	3.00	4.00
3.70	3.0	3.7	3.00	4.00
-3.30	-3.0	-3.3	-4.00	-3.00
-3.50	-3.0	-3.5	-4.00	-3.00
-3.70	-3.0	-3.7	-4.00	-3.00
3.45	3.0	3.5	3.00	4.00

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[choroba]: I'm curious which part of your signature do they find offensive.
[LanX]: they?
[LanX]: click!
[choroba]: they
[LanX]: why do you think it's more than one person?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-05-24 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?