6/28/2019 0 Comments Round Up 1Yes I know why we always round to the nearest even number if we are in the exact middle (i.e. 2.5 becomes 2) of two numbers. But when I want to evaluate data for some people they don't want this behaviour. What is the simplest method to get this: to be 1,2,3,...,10 and not 0,2,2,4,4,...,10. Edit: To clearify: 1.4999 should be 1 after rounding. (I thought this would be obvious)
jakob-rjakob-r
5 AnswersHow to Round a Number. Rounding a number is when you take a number and 'bump it up' or 'bump it down' to a nearby and 'cleaner' number. A number can be rounded to any place value you want. If you type in a number you wish to round below, and select what place value you want to round it to, this selection will show you how to round it! @ in the holidays for revision. Round-up has clear instructions and simple grammar boxes, so students can study at home without a teacher. The Round-up Teacher's Guide includes a full answer key and four tests plus answer keys Pearson Education Limited Edinburgh Gate, Harlow Essex CM20 2JE England and Associated Companies throughout the world. This is not my own function, and unfortunately,
An Example
A5C1D2H2I1M1N2O1R2T1A5C1D2H2I1M1N2O1R2T1
If you want something that behaves exactly like
flodelflodel
This appears to work: Ananda Mahto's response seems to do this and more - I am not sure what the extra code in his response is accounting for; or, in other words, I can't figure out how to break the rnd() function defined above. Example:
user1854990user1854990
As @CarlWitthoft said in the comments, this is the IEC 60559 standard as mentioned in ![]() Note that for rounding off a 5, the IEC 60559 standard is expected to be used, ‘go to the even digit’. Therefore round(0.5) is 0 and round(-1.5) is -2. However, this is dependent on OS services and on representation error (since e.g. 0.15 is not represented exactly, the rounding rule applies to the represented number and not to the printed number, and so round(0.15, 1) could be either 0.1 or 0.2). An additional explanation by Greg Snow: The logic behind the round to even rule is that we are trying to represent an underlying continuous value and if x comes from a truly continuous distribution, then the probability that x2.5 is 0 and the 2.5 was probably already rounded once from any values between 2.45 and 2.54999999999999..., if we use the round up on 0.5 rule that we learned in grade school, then the double rounding means that values between 2.45 and 2.50 will all round to 3 (having been rounded first to 2.5). This will tend to bias estimates upwards. To remove the bias we need to either go back to before the rounding to 2.5 (which is often impossible to impractical), or just round up half the time and round down half the time (or better would be to round proportional to how likely we are to see values below or above 2.5 rounded to 2.5, but that will be close to 50/50 for most underlying distributions). The stochastic approach would be to have the round function randomly choose which way to round, but deterministic types are not comforatable with that, so 'round to even' was chosen (round to odd should work about the same) as a consistent rule that rounds up and down about 50/50. If you are dealing with data where 2.5 is likely to represent an exact value (money for example), then you may do better by multiplying all values by 10 or 100 and working in integers, then converting back only for the final printing. Note that 2.50000001 rounds to 3, so if you keep more digits of accuracy until the final printing, then rounding will go in the expected direction, or you can add 0.000000001 (or other small number) to your values just before rounding, but that can bias your estimates upwards. Depending on how comfortable you are with jiggling your data, this works:
MichaelChiricoMichaelChirico
Not the answer you're looking for? Browse other questions tagged rroundingr-faq or ask your own question.
0 Comments
Leave a Reply. |