Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Round up 3 values to the next 100

by siva kumar (Pilgrim)
on Feb 14, 2007 at 07:13 UTC ( [id://599868]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Round up 3 values to the next 100
in thread Round up 3 values to the next 100

I might have done this
$num = 235634; if (length($num) >=3 ) { $var = substr($num,-2,2); if ( !$var eq '00') { $var1 = 100 - $var; $num += $var1; } print $num; }

Replies are listed 'Best First'.
Re^4: Round up 3 values to the next 100
by bobf (Monsignor) on Feb 14, 2007 at 07:26 UTC

    If you tested that you might be surprised at what it actually does. I'll give you a hint: what does if ( !$var eq '00' ) really mean? (See perlop and look at the table of precedence...)

    You might also want to specify how negative numbers should be rounded. If -12345 should round to -12300, my solution will work but the approach you outlined will produce different results.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://599868]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found