P is for Practical PerlMonks

### Re: Best way to round a number.

 on Oct 25, 2012 at 00:06 UTC ( #1000738=note: print w/replies, xml ) Need Help??

in reply to Best way to round a number.

Why would 33 be rounded down to the nearest lower multiple of 5; and 36 be rounded up to the nearest higher multiple of 5? (Ditto: 33 down to 30; but 3 up to 5?)

Replies are listed 'Best First'.
Re^2: Best way to round a number.
by Anonymous Monk on Oct 25, 2012 at 00:37 UTC
Alright, forget the multiple of 5 thing, its to the nearest 5 per say; therefore 33, should go to 30 because of the logic on the sample code I gave here, if the last number in this case is 3 (from 33), is less than five it should go to 30. So number 11 should go down to 10, 17 should round up to 20, I hope I am a lil clear on that now, thanks!
I hope I am a lil clear on that now, thanks!

Not really. Are you saying that

1. if it is less that xx5, it rounds down.
2. if it is greater than xx5 it rounds up.
3. But if it is equal to xx5, it stays as is?

If so, that is a very peculiar rounding mode?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

How is 33 closer to 30 than to 35?

30 31 32 33 34 35

I count two numbers between 30 and 33, but only one number between 33 and 35. Clearly 33 is closer to 35.

Create A New User
Node Status?
node history
Node Type: note [id://1000738]
help
Chatterbox?
 [erix]: still doesn't work? [afoken]: sorry, forget File::BOM. I did not see DBD. [ELISHEVA]: perldoc - of course [erix]: hm, where's tux when you need him? [ELISHEVA]: what's curiouser is that the underlying Text::CSV_XS appears to be BOM-friendly [afoken]: DBD::CSV has a csv_class attribute. You could subclass Text::CSV_XS to handle BOMs, e.g. through File::BOM. [ELISHEVA]: Text::CSV_XS already can handle boms - see its detect_bom flag [ELISHEVA]: but it seems that the DBD::CSV layer on top of it doesn't [afoken]: Also: All other attributes that start with csv_ and are not described above will be passed to Text::CSV_XS (without the csv_ prefix). [Discipulus]: what about a good 'ol SOPW?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-05-28 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (192 votes). Check out past polls.