Opinions on rounding

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?

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

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

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

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.

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

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.)

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.