I'm afraid this is more answering "do you have any idea?" rather than giving a solution.
The primary issue here is your locale, as mentioned in your comment on the question. Custom number formats are not agnostic to the locale-specific number formats. In the case of the UK locale, commas are regarded as thousands separators, and periods are regarded as decimal separators. So your custom format #,#" days"
is essentially just instructing Sheets to format with a comma as a thousands separator, with no decimal places (it is functionally equivalent to #,###" days"
.
As you saw, when you directly enter 1,5
, this isn't formatted at all, because in the UK locale this is not recognised as a valid number (or date, or anything numeric), and is stored as a text string.
So an option is to change to a locale that uses a comma as a decimal separator (eg Italy). However (and this is a big "however") I have had a lot of trouble getting the custom formats to work in such locales; the implementation appears to leave a bit to be desired.
Another option is to keep your current locale, and make do with a period for a decimal separator, and use the format #.# "days"
. The "however" here is that the decimal point is included even when it is not needed (ie whole numbers), which is irritating, and I don't know of a workaround in Sheets using custom formatting alone.
A third option is to use spreadsheet formulae to reproduce the values in the appropriate format. The reproduced data would be text strings, so you should still reference the raw values (which might be in a column that could be hidden) in formulae. Downside is of course the duplication of data and reduced usability.
And lastly, Google Apps Script could auto convert values to text strings in the desired format; again you would have to consider formulae that reference these cells.
I hope this gives some insight, and I really hope to be able to delete this answer if someone has a watertight solution that can be achieved in custom formatting alone.
Look into the following functions: IF and CONCATENATE.
Taking the frequency as an example: you have one cell, B23 in this example, that contains your "raw" number. 2.2 GHz would be entered as 2200000000. Your sheet will be sortable by this column.
Then in C23, put this formula:
=if(B23>=1000000000,B23/1000000000,if(B23>=1000000,B23/1000000,if(B23>=1000,B23/1000,B23)))
In D23, this formula:
=if(B23>=1000000000,"GHz",if(B23>=1000000,"MHz",if(B23>=1000,"kHz","Hz")))
And in E23, this formula, which produces your formatted value:
=concatenate(C23," ",D23)
You don't actually need three cells. You can have just one cell, putting the IF functions in the parameters of the CONCATENATE function:
=concatenate(if(B23>=1000000000,B23/1000000000,if(B23>=1000000,B23/1000000,if(B23>=1000,B23/1000,B23)))," ",
if(B23>=1000000000,"GHz",if(B23>=1000000,"MHz",if(B23>=1000,"kHz","Hz"))))
Using three cells just makes it easier to keep things straight, especially the first few times you use nested functions.
For values using binary prefixes (traditionally used for memory sizes), the factors change to 1024, 1024 squared, etc. Note that the prefix for 1000 is lowercase "k" while for 1024 it is uppercase "K"; M and G are always uppercase.
Best Answer
The following custom number format mask will produce the desired results without losing the accuracy of the underlying value.