CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Function for rounding up

 



benchivers
Novice

Mar 29, 2002, 4:15 AM

Post #1 of 3 (268 views)
Function for rounding up Can't Post

Is there a function to round up decimal numbers, or to have a number to two decimal places?

If so, could someone give me an example.

Many Regards,
Ben Chivers


Paul
Enthusiast

Mar 29, 2002, 5:14 AM

Post #2 of 3 (267 views)
Re: [benchivers] Function for rounding up [In reply to] Can't Post

my $num = '12312.325235';

print sprintf "%.2f", $num;

You could also use POSIX::ceil for rounding up.


(This post was edited by RedRum on Mar 29, 2002, 5:17 AM)


mhx
Enthusiast / Moderator

Mar 29, 2002, 9:17 AM

Post #3 of 3 (261 views)
Re: [RedRum] Function for rounding up [In reply to] Can't Post


In Reply To
print sprintf "%.2f", $num;


... or just ...

[perl]
printf "%.2f", $num;
[/perl]

-- mhx

At last with an effort he spoke, and wondered to hear his own words, as if some other will was using his small voice. "I will take the Ring," he said, "though I do not know the way."

-- Frodo


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives