Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Question on rounding

  • 02-10-2008 11:09am
    #1
    Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭


    OK, having a slight disagreement with our contractor/programmer here about a rounding issue in a program. I think it's actually a programming question more than a mathematical one, as I have to bow to programming conventions more than other ones.

    It's worth noting that the programmers are all in a foreign country.

    The problem we reported to them was that a program was incorrectly rounding down numbers. For example, given a number of 100.3845, it was rounding this to two decimal places and giving 100.38. Which looks clearly wrong in my eyes.

    However after looking at wikipedia, it claims that in rounding, all you do is look at the digit after the one you want to keep and round based on that. So in the above example, because the third digit is 4, you round down to .38.

    I can distinctly remember in my schooling though that this is *not* how you round. Rounding involves "rolling up" the number, so 100.3845 rounds to 100.385 which rounds to 100.39. I've asked other Irish people here in work, and they all agree it rounds to .39

    Who's right? And what do programming languages do?


Comments

  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    seamus wrote: »
    OK, having a slight disagreement with our contractor/programmer here about a rounding issue in a program. I think it's actually a programming question more than a mathematical one, as I have to bow to programming conventions more than other ones.

    It's worth noting that the programmers are all in a foreign country.

    The problem we reported to them was that a program was incorrectly rounding down numbers. For example, given a number of 100.3845, it was rounding this to two decimal places and giving 100.38. Which looks clearly wrong in my eyes.

    However after looking at wikipedia, it claims that in rounding, all you do is look at the digit after the one you want to keep and round based on that. So in the above example, because the third digit is 4, you round down to .38.

    I can distinctly remember in my schooling though that this is *not* how you round. Rounding involves "rolling up" the number, so 100.3845 rounds to 100.385 which rounds to 100.39. I've asked other Irish people here in work, and they all agree it rounds to .39

    Who's right? And what do programming languages do?

    The program is right. Plot the points on a numberline and you'll see which one it is nearer.

    And I don't know where you went to school but that method of rounding is 100% wrong:p You only look at one significant digit.

    Programming languages will do more or less what you tell them to;)


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Yeah, I've talked to colleagues about it here and although most of us came up with the same answer, that doesn't seem to be the way it's normally done.

    It's technically not wrong, though there's a greater loss of precision in doing the "rolling up" method which seems to have been taught to almost everyone in this country....

    Bizarre. That's my revelation for this decade.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Rounding to second significant digit is based on the third digit.

    Simply because you are doing 1 level of rounding.. For all intents and purposes.. .45 rounded to the nearest whole number is 0 hence why it stays at 100.38


  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    seamus wrote: »
    It's technically not wrong, though there's a greater loss of precision in doing the "rolling up" method which seems to have been taught to almost everyone in this country....
    It is.

    Over even a medium sample of data rounded in this way, it would completely bias the results.


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    seamus wrote: »
    I can distinctly remember in my schooling though that this is *not* how you round. Rounding involves "rolling up" the number, so 100.3845 rounds to 100.385 which rounds to 100.39. I've asked other Irish people here in work, and they all agree it rounds to .39

    Who's right? And what do programming languages do?

    I remember that way from school aswell. But in the real world is the other way :).

    Excel/SQL/VB and pretty much any other lang I've used all would return 100.38 when rounding your example.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Doesnt excel use Swedish Rounding in its rounding methods .. or where did I read that


  • Closed Accounts Posts: 1,015 ✭✭✭Epic Tissue


    I was taught the same as the OP. The lying bastards!


  • Registered Users, Registered Users 2 Posts: 6,465 ✭✭✭MOH


    seamus wrote: »
    Yeah, I've talked to colleagues about it here and although most of us came up with the same answer, that doesn't seem to be the way it's normally done.

    It's technically not wrong, though there's a greater loss of precision in doing the "rolling up" method which seems to have been taught to almost everyone in this country....

    Bizarre. That's my revelation for this decade.

    It's technically very wrong. And it doesn't make any sense.

    Based on that logic, 444.444444445 rounded to the nearest thousand would be 1000 instead of 0.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    i don;t know where you all went to school but i went to school in Co. Wicklow and we were though the correct way i.e. 100.3845 rounds to 100.38

    what programming language are you using ? VB for instance uses bankers rounding so in certain cirumstances a number when rounding VB may round up instead of down.

    EXcel uses a different kind of rounding


  • Registered Users, Registered Users 2 Posts: 2,777 ✭✭✭shanew


    there are different kinds of rounding but the two most common are arithmetic round which .5 and over rounds up, everything below this rounds down. This type of rounding is used in maths/engineering etc.

    The other main type of rounding is 'Banking round' referred to earlier - this is supposed to alternate the rounding on _exact_ .5s up then down.

    For many real-world financial applications - e.g. Invoicing etc, you have to use arithmetic rounding or the VAT totals cause problems..



    Shane

    amen wrote: »
    i don;t know where you all went to school but i went to school in Co. Wicklow and we were though the correct way i.e. 100.3845 rounds to 100.38

    what programming language are you using ? VB for instance uses bankers rounding so in certain cirumstances a number when rounding VB may round up instead of down.

    EXcel uses a different kind of rounding


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    Is it true that banks round up/down in favour of the customer then in favour of the bank, on alternate conversions??


  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    Is it true that banks round up/down in favour of the customer then in favour of the bank, on alternate conversions??

    I do know that Barclays ended up with several million of their customers money one year due to their rounding. In the end they gave it to charity, so this method does make some sense.


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    From my own schooling, and when working out calculation on paper, if its above .5 round up, below round down. When I program, it depends on what is needed

    There are different rounding methods for a very important reason, that being that no one method will suit all circumstances. Like most things that have many ways of doing them!

    If your unhappy with their choice of rounding method, inform them of that, and tell them what method/solution you would prefer them to use.

    If they are professional, their should be no quibble other than them pointing out to you the ramifications of this change (and working out a price for the change as this obviously wasn't discussed at this technical level in the contract and that it was assumed incorrectly that a certain format be used).

    No one is at fault, but its something to think about next time. It's nothing to do with their "foreigness" either however, that being said, they obviously didn't go to the same school as you ;)


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    I'm sorry but I've been reading this thread and I'm wondering if it's a joke. I don't know where you were schooled OP but there is no school in Ireland that teaches anyone to round on anything other than the n+1 point (where n is the number of places you wish to round to). There is a principle called floor and ceiling (which can basically be referred to as rounding down and rounding up) but this is not taught in primary or secondary schools in the republic. Programming being a mathematical science rounding will follow normal mathematical rounding principles. Can you explain why you would want a program to round up to the next number??


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    ianhobo wrote: »
    No one is at fault, but its something to think about next time. It's nothing to do with their "foreigness" either however, that being said, they obviously didn't go to the same school as you ;)
    And half of the rest of this country ;)

    I mentioned the foreign bit purely to try and figure out whether it was a quirk/failing of the Irish curriculum or a bizarre cultural difference. It is of course, the former.

    Naturally, it's not a case of doing it "our way", it's a case of doing it properly. My job is to act as a filter between the business wanting to do it their way, (i.e. overly complicated and nonsensical) and it being logged to the developer as a workable, sensible and above all, correct solution or request.

    It's part of a financial program, so accuracy is quite important. The person who made the initial complaint/report was still unable to grasp that her calculations were wrong when I explained it to her.
    I'm sorry but I've been reading this thread and I'm wondering if it's a joke. I don't know where you were schooled OP but there is no school in Ireland that teaches anyone to round on anything other than the n+1 point (where n is the number of places you wish to round to).
    Clearly there are quite a lot of schools that teach the other method and a whole pile of examiners who fail to spot the error too. In fact, the majority of those I've spoken to in work were taught in this way.

    Having been corrected, I now know that the normal method is more correct, it's just one of those things that I was taught at such a young age that I took it for granted for the last 20 years :)
    Can you explain why you would want a program to round up to the next number??
    Well, there are plenty of reasons why you would want a program to round up a caculation. In this case, I didn't.


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    seamus wrote: »
    And half of the rest of this country ;)

    I mentioned the foreign bit purely to try and figure out whether it was a quirk/failing of the Irish curriculum or a bizarre cultural difference. It is of course, the former.

    Naturally, it's not a case of doing it "our way", it's a case of doing it properly. My job is to act as a filter between the business wanting to do it their way, (i.e. overly complicated and nonsensical) and it being logged to the developer as a workable, sensible and above all, correct solution or request.

    It's part of a financial program, so accuracy is quite important. The person who made the initial complaint/report was still unable to grasp that her calculations were wrong when I explained it to her.

    Clearly there are quite a lot of schools that teach the other method and a whole pile of examiners who fail to spot the error too. In fact, the majority of those I've spoken to in work were taught in this way.

    Having been corrected, I now know that the normal method is more correct, it's just one of those things that I was taught at such a young age that I took it for granted for the last 20 years :)

    Well, there are plenty of reasons why you would want a program to round up a caculation. In this case, I didn't.

    Have you considered that you weren't taught the wrong way to round numbers and that you have just forgotten how to do it?

    I suspect you don't remember what colour the tractor was in Ann and Barry Go to the Farm either, but you wouldn't blame that on the school system in Ireland!


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Draupnir wrote: »
    Have you considered that you weren't taught the wrong way to round numbers and that you have just forgotten how to do it?
    I did consider that, and I'm 100% sure that's not the case :)
    I suspect you don't remember what colour the tractor was in Ann and Barry Go to the Farm either, but you wouldn't blame that on the school system in Ireland!
    I haven't seen an Ann and Barry book in 20 years. I have however, been carrying out rounding in my head manually on a regular basis in that time :)


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    seamus wrote: »
    I did consider that, and I'm 100% sure that's not the case :)

    I haven't seen an Ann and Barry book in 20 years. I have however, been INCORRECTLY carrying out rounding in my head manually on a regular basis in that time :)

    FYP!!


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    It's just a reduction in accuracy as I mentioned above. ;)

    Decimals is the science of imprecision.

    Look at it this way: if you were performing a calculation on 0.245 and you reduced it to two decimal places, you would get 0.25. If you were then to reduce it to one decimal place later on in the calculation, you would get 0.3.

    But if you were to reduce it to one decimal place the first time and otherwise do the same calculation, you would have gotten 0.2. So both are technically imprecise, but the former is more imprecise than the latter :)


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    You shouldn't reduce the precision of any decimal value whilst in the middle of a calculation. Maintain the precision until you get the result and then do your rounding or reduce to the desired number of decimal places.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    You shouldn't reduce the precision of any decimal value whilst in the middle of a calculation

    that is not necessarily true either
    depends on what you are doing
    for instance if I am calculating an insurance rate I don;t really care about 1000's of a cent if the answer is in euros but
    if I am doing a currency conversion from euro to dollars of 10,000s then I care about those 1000's of a cent


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    amen wrote: »
    that is not necessarily true either
    depends on what you are doing
    for instance if I am calculating an insurance rate I don;t really care about 1000's of a cent if the answer is in euros but
    if I am doing a currency conversion from euro to dollars of 10,000s then I care about those 1000's of a cent

    I don't see your point, lets think about this based on two criteria:

    1. Accuracy of results

    If you don't round values until you have your final total, you should in theory maintain the accuracy of your result. Agreed?

    2. Performance of the Algorithm

    Whether or not you care about the 1000's of a cent is irrelevant, if you are rounding values within the algorithm then this is unnecessary work which will hit the performance of the algorithm since many roundings are being carried out when a single rounding at the end will achieve the same, if not a better result, with better performance. Agreed?


Advertisement