Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How do I round a number?

by powerman (Friar)
on Apr 23, 2002 at 11:44 UTC ( [id://161255]=note: print w/replies, xml ) Need Help??


in reply to How do I round a number?

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://161255]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found