Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Dividing and format

by Abigail-II (Bishop)
on Nov 27, 2003 at 14:14 UTC ( [id://310539]=note: print w/replies, xml ) Need Help??


in reply to Dividing and format

What's the problem with using printf? Anyway, the following code seems to work (although it doesn't do 'Bankers rounding'):
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my $o = $_; next if /\D/ || /^$/; substr $_ => -0, 0, 0 x (4 - length); $_ ++ if 50 <= substr $_ => -2, 2, ""; substr $_ => -1, 0, "."; print "$o / 1000 = $_\n"; } __DATA__ 12000 12678 5 49 50 499 500 501 12000 / 1000 = 12.0 12678 / 1000 = 12.7 5 / 1000 = 0.0 49 / 1000 = 0.0 50 / 1000 = 0.1 499 / 1000 = 0.5 500 / 1000 = 0.5 501 / 1000 = 0.5

Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found