Opinions on rounding

  1. 2 months ago

    Dale A

    Mar 15 San Diego, California, USA

    I'm having a "friendly discussion" with a friend about the proper response to rounding to the nearest value. I'd like to know if there is a set standard for the return value as well as anyone's opinions on it.

    Given a double value such as 2340.204 and the specified number of decimal places = 2, with the return value declared to be a string, should a RoundNearest method return "2340.2" or "2340.20"? Essentially, should that trailing zero be included in the returned string?

  2. Dave S

    Mar 15 San Diego, California USA

    there is no difference. Numbers do not have leading or trailing spaces.... Display formats however do.... and since a Round Function is not a display function then no trailing zero should be expected

  3. Kem T

    Mar 15 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    It should return ".2". If you want something else, use Format to be specific.

  4. Alberto D

    Mar 15 Pre-Release Testers

    The only time I see something like 2340.20 is when it is about money, anywhere else it will be 2340.2

  5. Christian S

    Mar 15 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    The trailing 0 is very important to show it was rounded to 2 digits after the decimal dot.
    Otherwise you don't know whether it's .15 rounded or .201 rounded.

  6. Douglas H

    Mar 15 Pre-Release Testers, Xojo Pro

    @Dale A I'm having a "friendly discussion" with a friend about the proper response to rounding to the nearest value. I'd like to know if there is a set standard for the return value as well as anyone's opinions on it.

    My opinion is that the nice thing about standards is there are so many to choose from! :)

    In all seriousness, to me the "proper response" depends on context. When dealing with columns of number that are right aligned, I often prefer to format with the same number of decimals. Even if not a monetary amount. But that is just one example. To me the "proper response" is entirely dependent on context. And which "set standard" to apply.

    For that matter, there are a surprising number of ways to "round" a number too. For example, for a long time I did not know there was a "Banker's Rounding" standard that was different from how I had always treated rounding. (See here for one explanation.)

  7. Dale A

    Mar 15 San Diego, California, USA

    Thanks, all. I, too, tend to think that since rounding is a numeric function the trailing zero should be added in the formatting for display, if necessary. That would keep the rounding methods consistent regardless of whether the return value is a String or a Double.

or Sign Up to reply!