Specific number FORMAT mask like #,###,##0.0### that would force Excel GENERAL NUMBER format? - excel

What custom format mask will display 3.0 as 3 and 3.10 as 3.1?
I am trying to support a Cognos report that uses custom SQL that selects from an Oracle column that is defined as NUMBER(11, 4). if I do not apply any formatting to the.1 column on the report, the resulting Excel column has "Number " category formatting applied with 4 decimals.
As a result, I see the following sample formatted values displayed:
a) 4,123.3400
b) 4.0123
c) 4.0100
d) 3
e) 0.10000
I would prefer to see only significant zeros afer the decimal point displayed. For example, 4.0100 should be 4.01 but otherwise the formatting is fine. When the number is a whole number, I prefer not to display a decimal point at all. For example, 3 is preferable to 3.0 for values with no fractional part.
I tried experimenting with custom formats and the closest that I can come to what I am looking or is this format
#,###,##0.0###
which produces:
a) 4,123.34
b) 4.0123
c) 4.01
d) 3.0
e) 0.1
There are two differences between using no format, the first example and my custom format:
Whole numbers are displayed with one zero after the decicimal (d)
Trailing insignificant zeros after the decimal are suppressed. (a)
What I woold like to see is the following, the difference with the opreceding example is that whole numbers are displayed without any decimal (d):
a) 4,123.34
b) 4.0123
c) 4.01
d) 3
e) 0.1
Excel acheives this by default with its "General" format, however, the trick is trying to get Cognos to produce that setting using custom SQL that selects from a NUMBER(11, 4) column. As mentioned above, going with the default format results in Excel output that uses the General format but has 4 decimal places, so I get 4 decimals of precision if there is any faction part. The csolution appears to be to use a custom format.
Can my format
#,###,##0.0###
be tweeked to work like Excel's General format for numbers?

The answer is no, you can't get all the formatting you want with one single format.
You should know that even Excel's General does not get everything you want, because that doesn't provide thousands separators.
You'll have to pick something to give up. If you can give up the commas, then why not just use General?
Also note that you have superfluous # marks. Your formatting is equivalent to #,##0.0###.
See this related question for potential further ideas.

Related

excel power query transforming data from text to decimal

Howto transform a colum with postive and negative values, which is loaded as text into a column with decial values without errors. the minus sign seems to make the error:
I use a german version of excel 365 on windows 10
Finally solve the problem: It was q quircky minus-sign, which had to be replaced by a standard minus sign before changing type to decimal. Unfortunatley at first sign this quirky decimals looked like nomral ones

How to use =LEFT and =LEN function with scientific notation in Excel VBA?

I'm trying to write an Excel macro using VBA that will return only the first 5 numbers in a cell when the length of that cell exceeds 20. The field normally returns 15-digit alphanumeric results (which I need to leave alone) but in certain exceptions will return a 5-digit number with a multitude of zeroes following it (1234500000000000000000000...) which Excel converts into scientific notation (1.2345E+160). I am able to convert the cells to numbers instead of scientific notation and view the whole number.
I've tried to use code such as =IF(LEN(A1)>20,LEFT(A1,5),A1) and it just returns 1.2345E+160. Even though the whole number is displaying, Excel still thinks the cell length is 11 and won't display the first 5 digits.
I've also tried lines such as =IF(A1="E",LEFT(A1,6),A1) thinking it would detect the E, return 1.2345, and I could just remove the decimal points, but that didn't work either (it just returns the original 1.2345E+160).
I got the same results whether the cell was formatted as number or text. Is there a way around this?
Thank you for your time!
You are trying to use string manipulation on a number. Instead use math:
=A1/1E+160
If you do actually want to treat this thing as text, understand that the underlying value being stored is your 12345000000000000... and there is no decimal point in that thing. So you'll have to convert to text and add the decimal:
=LEFT(TEXT(A1,"0"), 1) & "." & MID(TEXT(A1,"0"), 2, 4)
But that's pretty ugly. I would just stick with math.

Trying to show only a certain amount of numbers

To make the sale to my customer I need to import numbers from a report into an Excel document. For example the number coming in will be 14.182392. The only reason for my guy not to buy the product is because he only wants to view 14.182 on the Excel sheet. Okay so the other catch is, the number CANNOT be rounded in any shape or form.
So what I need is a way to just show so much of number, WITHOUT ROUNDING.
Is this possible? Any ideas of how I could get around this would be fantastic.
Please try:
=TEXT(INT(A1)+VALUE(LEFT(MOD(A1,1),5)),"00.000")
Firstly =TRUNC is a better answer (much shorter). My version was connected with uncertainty in your requirement (it is odd!) and in the hope it might be easier to adjust if not exactly what you/your boss wanted.
TRUNC literally just truncates the decimals (no rounding!) to a length to suit (ie 3 if to show nn.182 given nn.182392 or say nn.182999).
LEFT may also be a better choice, but that depends upon knowing how large the integer part of your number is. =LEFT(A1,6) would display 14.189 given say 14.189999 in A1. However it would show 1.4189 given 1.4189999 in A1 (ie four decimal places).
The formula above combines text manipulation with number manipulation.:
INT takes just the integer value (here 14.)
MOD takes just the modulus – the residual that is not an integer after division, in this case by 1. So just the .182392 part. LEFT is then applied here in a similar way to as used above, but without needing to concern oneself with the length of the integer part of the source value (ie 14 or 1 etc does not matter).
VALUE then converts the result back into numeric format (string manipulation functions such as LEFT always return text format) so our abbreviated decimal string can then be added to our integer.
Finally, the TEXT part is for formatting but is hard or impossible to justify! About the only use is that it displays the result left-justified in the cell – perhaps a little warning that the number displayed is not the “true” value (eg it won’t SUM) because, as a result of a formula, it won’t be marked with a little green warning triangle.
The displayed values can use the TRUNC function like this,
=TRUNC(A1, 3)
But you must use A1 in any calculations to retain the precision of the raw value.
Easiest way I know:
=LEFT(A1; x)
where x = the amount of characters You want. Mind that the dot counts as a character as well.

Why do Excel values in parentheses become negative values?

A colleague and I encountered a behavior in Excel which isn't clear to us.
Background:
We have a tool which converts an Excel sheet into a table format. The tool calculates the formulas which are in excel and replaces variables inside it with specific values.
The excel tool is used by one of our customers who use values like (8) or (247).
These Value are automatically translated by excel to -8 or -247.
Question:
I saw that many people want to display negative numbers in parentheses. But why would Excel change values in parentheses to a negative number?
I know that I could simply change the cell config to text and this would solve the problem but I wonder if there is a reason for the behavior, since there seems to be no mathematical reason for this.
Its simply the different format of cells you are bringing the "values from" and "pasting to". ..... numbers with parentheses are in cells with "accounting" format and negatives are stored in general or standard number formated cells. To resolve you can change the format of destination cells to accounting using cell formatting as number>accounting.
To answer the why, it's because accountants put negative numbers in brackets for readability
Unfortunately, this is one of the excel feature/bugs that helps some folks and frustrates others. When opening a file or pasting content, excel will immediately and always try to parse any values into formats it deems appropriate, which can mess up data like:
Zip Codes / Tel. # → Numeric: 05401 → 5401
Fractions → Dates: 11/20 → Nov, 20th YYYY
Std. Errors → Negative Numbers: (0.1) → -0.1
For some workarounds , see Stop Excel from automatically converting certain text values to dates
Once the file is open/pasted, the damage is already done. At that point, your best bet is:
Updating the field and displaying as text (appending with ') to prevent re-casting
Formatting the field if the operation wasn't lossy and is just presenting the info differently
Running a clean if/else to pad or other convert your data based on the identified errors
Specific to displaying values back in parens, if excel is converting them and treating them like negative numbers (which may or may not be the appropriate way to actually store the data), you can apply a different format to positive and negative numbers to wrap back in parens.
It is standard practice to write negative values as numbers in parentheses, especially in accounting. This makes negative values stand out much more than a simple negative hyphen; compare -1 and (1).
Excel is a tool very commonly used by accountants and supports accountant-style spreadsheets. Therefore, entering (100) means having a value of -100, even if there is no minus hyphen!
Here is a fun fact, if you enter (-10), Excel will treat it as normal text.

Display, sort and filter numbers with multiple decimal in excel 2007

I'm using excel 2007.
I've a list of tasks (200-500) that I need to group in different category/section etc (multiple filters). Whole data is in excel table so I can apply Excel's build-in table filters to display exact data that I need.
However it is always difficult to apply multiple filter to display expected data, specially as I need to do it very frequently. To make things simple I'm planning to number each record like
a.b.c.d.e.f
Where a, b, c, d, e, f are simple numbers. List looks like:
1
1.1
1.2
1.2.1
1.2.1.1
1.2.2
1.3
& so on.
Problem is, Excel take it as number with single decimal but as soon as I add second decimal, excel treat it as text, which is obvious in general behavior.
However, as special case, I need excel treat both as number or text. Number is preferable as I want to sort them, which might be difficult as a text.
To make the things little more complex, while filtering in table, I require if I can add some formula to filter results like 1.* should display all numbers starts with 1.
Is it possible with excel's default behavior, without VBA?
If no, is it possible with VBA? If yes, any clue is appreciated. I don't need whole program as I can write basic VBA program, just a clue how it can be done?
I sort mine by adding a helper column that adds a letter to the front and sort on that. E.g. 1 becomes f1, 1.1 becomes f1.1 etc. Then all are sorted as text.
You can use the formula ="f" & A1.
My sample:
Then the data sorted:
And the filter:
If I were to try this without VBA, my first step would be to use the sort to columns function on the data tab.
Next make sure all empty spaces in your data are filled with zeros.
Then sort the data by column
as long as you left your original data in the same row as the sorted data (I didn't in the images posted to focus on the process), your items should now be in order.

Resources