Link to home
Start Free TrialLog in
Avatar of Hugo R
Hugo R

asked on

How to round to 0, 5 or 9 which ever is closest?

How to round to 0, 5 or 9 which ever is closest?
Avatar of CompProbSolv
CompProbSolv
Flag of United States of America image

Are you referring to the first decimal digit, the units digit, or the number itself?  How do you deal with "ties" (round up or down)?  For example, to what would you want 10.7 rounded?  I could imagine 10.5, 10.9, or 9 depending on your other rules.
Avatar of Hugo R
Hugo R

ASKER

To the number itself, 10.7 should be just a 10
If you wanted to round the number itself, you'd round to 9,  10 wasn't in the list of rounding.  Are you referring to the units digit (the "0" in "10")?  If so, to what would you want 7 rounded?
Avatar of Hugo R

ASKER

Up to a 9
This could be done with a complex Choose function or with VLookup.  The key is to separate off the units digit, decide if it should be 1, 5, or 9 (using Choose or VLookup), then replace the units digit of the original number with the new digit.
int(number) - Mod (number,10) will give you the digit with which to work, call it unit
choose(unit, 0,0,0,5,5,5,5,5,9,9) will give you 1, 5, or 9 (I assumed you want 7 to return 9), call it NewUnit
Mod (number,10) + NewUnit will give you the result
I was incorrect.  My assumption was to change 7 to 5, not 9.  To change 7 to 9 use: choose(unit, 0,0,0,5,5,5,5,9,9,9)

You could wrap those three lines into one (rather ugly!) statement if you wish.
Avatar of Hugo R

ASKER

This is for Google Spreadsheets?
Don't know.  I saw "spreadsheets" and assumed Excel.
I would hope that Google spreadsheets had something similar.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.