Question:

How do u make perl to round a number?

by  |  earlier

0 LIKES UnLike

I've made a program in perl and it's kind of a calculator, i want to make it so that it gives u an answer that is rounded. For ex.

1.94444+1=2.95, i want to round it like that

 Tags:

   Report

2 ANSWERS


  1. If you wish to round to say, 3 decimal places, you could do something like-

    $total = int(($total+0.0005)*1000)/1000


  2. Something like:

    printf("%.2f\n", 1.94444 + 1)

    Should print out "2.94."

    Hope this helps!

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions