Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Rounding over numbers

by Discipulus (Canon)
on Feb 15, 2016 at 08:45 UTC ( [id://1155240]=note: print w/replies, xml ) Need Help??


in reply to Rounding over numbers

Here my brutal attempt translating in perl what i'd say in plain language. Note the *10 at the begin and the /10 at the end: they make your life easier confining the problem to one digit only.
use strict; use warnings; print map { my ($int,$dec)=split /\./,$_*10; $dec = defined $dec && $dec >= 5 ? 1 : 0; sprintf("%.2f\n", ($int+$dec)/10); } (<DATA>); __DATA__ 1.24 13.25 2.90 2.99 2.92 14 # OUT 1.20 13.30 2.90 3.00 2.90 14.00

HtH

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-16 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found