Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: convert output from exponentional notation to normal

by kennethk (Abbot)
on Mar 19, 2013 at 15:58 UTC ( #1024327=note: print w/replies, xml ) Need Help??


in reply to convert output from exponentional notation to normal

Yes, as both previous posters said, printf/sprintf. The most flexible format choice is %g, which will swap between scientific notation and fixed decimal depending on precision and behaves most like Perl's default. %f means always use fixed decimal and %e means always use scientific.

In your case, I would probably also round numbers, since I have rarely seen the need for more the 3 significant figures for output outside of scientific computing. So my go to format here would probably "%.3g" for easy digestion, though %.8f is what meets your spec...

printf "%.8f\n", $counts / $total;


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024327]
help
Chatterbox?
[1nickt]: choroba That's why I asked if anyone is using it :-)
choroba only has used Moo from the htree
[1nickt]: Pardonm?
[choroba]: three
[choroba]: I mean I haven't used DBIx::Class nor M:S, only Moo
[1nickt]: Haha, I was learning about Linux filesystem trees trying to understand how Moo fits.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-11-24 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (349 votes). Check out past polls.

    Notices?