|
A very random question, but CPians' answers may possibly be useful for me...
Is there a word or a phrase describing this:
1.5 gets rounded to 1.
1.6 gets rounded to 2.
150 gets rounded to 100.
160 gets rounded to 200.
and any other similar effects...
Any suggestions greatly appreciated.
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
Are you directing those extra pennies to your own account?
|
|
|
|
|
If only!
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
I am not sure what you mean by "a phrase", but there's an overload [^] for Math.Round() method to tweak this behavior.
[EDIT]
Sorry, didn't notice:
PaulowniaK wrote: 150 gets rounded to 100.
160 gets rounded to 200. What type of application are you trying to write?
[/EDIT]
Whether I think I can, or think I can't, I am always bloody right!
modified 7-Sep-14 23:16pm.
|
|
|
|
|
I'm not able to disclose application details, but let's just say, the said behaviour already exists.
The trouble is how I would go about explaining what it's doing to the users.
Writing in the Help that "it rounds to the nearest integer" or "it rounds to the nearest 100" automatically suggests it does this:
1.4 turns into 1.
1.5 turns into 2.
1.6 turns into 2.
140 turns into 100.
150 turns into 200.
160 turns into 200.
etc. etc.
which isn't what happens.
Sure, I can explain this long hand, but I just wanted to know if there was a proper terminology to explain this.
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
How's this: Round to one significant digit.
|
|
|
|
|
Considering he needs 160.6 to be rounded to 200 and not 161.
Whether I think I can, or think I can't, I am always bloody right!
|
|
|
|
|
...or rounding to the most significant digit.
(I'd suggest that we call this "politicians rounding")
|
|
|
|
|
Rounding to one significant digit.
|
|
|
|
|
OK, bad example...
123 would be 120.
125 would be 120.
126 would be 130.
etc. etc.
The point not being the number of significant digits you end up with, but the fact that the rounding is happening at 5 and 6 rather than the more usual 4 and 5.
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
Sounds like you want to do Round Half Down + Significant then.
|
|
|
|
|
See my other answer, or Daves.
|
|
|
|
|
I think the word you are looking for is 'wrong'.
Software Zen: delete this;
|
|
|
|
|
http://en.wikipedia.org/wiki/Rounding[^]
"Round half down to nearest integral multiplier power of 10"
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
Thanks, "Round half down" was the term I was looking for.
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
how I would go about explaining what it's doing to the users. If you owe us money, we get more; if we owe you money, you get less.
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
This is standard rounding
The irony is that people are so used to bankers rounding they get confused when they see ordinary rounding, but this is the kind you probably learned about in school!
Disregard, I'm an idiot
modified 8-Sep-14 1:41am.
|
|
|
|
|
JMK-NI wrote: This is standard rounding
No it isn't.
There is a huge difference between standard rounding and significant rounding.
There are also many different types of rounding scheme depending on the application: http://en.wikipedia.org/wiki/Rounding[^]
|
|
|
|
|
Well knock me down!
It's 6:30AM, I haven't had coffee yet!
|
|
|
|
|
Well it's now 6:43am, my first meeting with my supervisory team was an hour ago and I have already spoken with my boss onshore, so the day is well underway.
Only another 14 or 15 hours still to go.
Feeling already.
|
|
|
|
|
JMK-NI wrote: Disregard, I'm an idiot Well, JMK-NI, don't worry too much: you are in the place for idiocy. It's kind of like a "contagious skin rash," here, on the Lounge, it breaks out in different people, and makes different people scratch in different places, while others scratch their heads.
cheers, Bill
“I have diligently numbered the days of pure and genuine happiness which have fallen to my lot: They amount to 14.” Abd-Ar Rahman III, Caliph of Cordoba, circa 950CE.
|
|
|
|
|
|
My understanding of rounding to N significant figure is like this:
1234 to 3 significant figures = 1230
1235 to 3 significant figures = 1240
1236 to 3 significant figures = 1240
The trouble is, I need
1234 to 3 significant figures = 1230
1235 to 3 significant figures = 1230
1236 to 3 significant figures = 1240
The point is, rather than rounding up or down depending on whether the N+1th digit is 4 or 5, but whether it is 5 or 6.
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
How about "N Significant Half-Down Rounding[^]"?
Whether I think I can, or think I can't, I am always bloody right!
|
|
|
|
|
Round half down + Significant.
|
|
|
|