Counting decimal places using Excel gives weird result - excel

I am trying to count the decimal places using a simple formula =LEN(A1-INT(A1))-2. The cell A1 is formated as Standard and contains e.g. the value 100.000739.
I don't understand why the formula returns 18 instead of 6?
=A1-INT(A1) ==> returns 0.000739 which is fine
=LEN(A1-INT(A1))-2 ==> returns 18
=LEN(0.000739) ==> returns 8 which is fine
Even if I explicitly formate the cell as a numer having 6 decimal places the formula still returns 18. Any idea?
Used version Microsoft Excel 2013

LEN returns the length of a string. A1-INT(A1) is a number, not a string.
Try
=T(A1-INT(A1)
and compare that with
=LEN(T(A1-INT(A1)))
That way you can see what value LEN is really using.

This works for me:
=LEN(A1)-FIND(".",A1)
if you have some integers in column A, then you will get an error as FIND will fail to find the decimal point. You can resolve that by first testing if the value in column A is an integer, and returning "0" in that case, like so:
=IF(A1=INT(A1),0,LEN(A1)-FIND(".",A1))

Related

Error in formula when comparing two separate formulas

I have the first and second formula to make sure the number I get is the same, which it is (32). The bottom formula however displays false and I have no clue why. (JA2 has a formula which outputs "32(22)"). Can anyone help me understand how they are not equal?
=LEFT(JA2,2)
=ISOWEEKNUM(TODAY())
=LEFT(JA2,2)=ISOWEEKNUM(TODAY())
LEFT returns a string ISOWEEKNUM returns a number. A string will not equal a number. Turn the string to a number:
=--LEFT(JA2,2)=ISOWEEKNUM(TODAY())
The -- or double unary is akin to -1*-1* which will change the string to a number if possible or return an error. So you may want to use IFERROR to deal with that possibility:
=IFERROR(--LEFT(JA2,2),60)=ISOWEEKNUM(TODAY())
Now if the Left is a string that cannot be converted to a number the formula will return 60 and since there can only be a max of 53 weeks it will return FALSE

Using formatted text as match function lookup value

My look up array is of format DI-0001. First 3 places are fixed as “DI-“ and next 4 are any number but of fixed length of 4. My look up array is a simple number which is less than 10000. Hence always equals to less than 4 digits. I formatted my lookup value column as “DI-“0000 so as to match the lookup array. But now my match function is breaking down, giving #N/A error. I understand the error, but don’t know how to overcome it.
You are not looking for a number in your look up array so you have to convert the value you are looking up to a string as well, not just format it as string.
=VLOOKUP("DI-"&TEXT(value,"0000"),array,2,0)
Or preferably,
=INDEX(B1:B9,MATCH("DI-"&TEXT(F1,"0000"),A1:A9,0))

Excel formula for count numbers of decimals

I need to count the numbers of decimals places of a number.
The A1 cell value is:
123456.78.
The formula in B1 is:
=LEN(MOD(A1,1))
The results of MOD(A1,1) is:
0.78
I expected the LEN to be 4 (LEN(0.78)=4).
The Excel formula calculates 17 because the forumula returns:
0.779999999998836
Should I try a different approach? For example looking for the separator char?
=LEN(A1)-FIND(".",A1)
Try this:
=LEN(RIGHT(A1;LEN(A1)-FIND(",";A1)))
A better formula managing a non decimal entry and different decimal separators:
=IF(ISNUMBER(FIND(".";A1));LEN(A1)-FIND(".";A1);IF(ISNUMBER(FIND(",";A1));LEN(A1)-FIND(",";A1)))
I see that the Len function is causing the math function to return the incorrect value for some reason (Len(Mod(123456.78, 1)) is returning 17 not 4, whereas Len(Mod(6.78,1) correctly returns 4).
You can add the TEXT function to your formula to change it to text, with a format of "General" to preserve the decimal precision, before calculating the length: LEN(TEXT(MOD(A1,1), "General")).
For those wanting to use this to calculate the number of decimal places without the leading "0.", simply subtract 2 from the result.

Right(text;5) is not the same as a 5 character text

I have a match function that I could not get working. I boiled it down to the point that it can't find the appropriate match since the values are not the same, apparently.
I have the value 21337 in cell D59. In cell S59 I have the function: Right($d59;5), which displays 21337. However when I enter in a cell: =D59=S59 i get the return FALSE.
I use the Right() function because cells in column D contain concatenated values, where the last 5 values are of importance. For example D60 contains 21337 - 21448, where 21448 is the value I want to match.
Anyone has a clue on what might be the problem?
With no formatting you'll see that 21337 is right aligned - showing this is a number and treated as a number by Excel.
On the other hand Right($d59;5) will show the number left aligned, indicating that the returned value is being treated as text by Excel.
If you try Right($d59;5)*1 Excel will implicitly convert the value back to a number (due to the calculation performed) and both values will be equal.
To be explicit about the conversion, as Brian has pointed out, use VALUE(Right($d59;5)).
If you use "Formula" > "Evaluate Formula", does it show the penultimate Evaluation as21337="21337"
The LEFT(..) function will convert the number to a string, and the string and the number will not equate. Try either =TEXT(D59,"#")=S59 or =D59=N(Left(S59)) to convert in your comparison, or change the code in S59 to =N(Right($D59,5)) to make S59 show a number
(The N(..) function converts a string to a number, returns 0 if Not A Number)

Get cell to the right of current month in Excel

I'm pretty new to Excel, that question is probably easy, but I dont know what to do :-(.
So this is what I have:
Date Numbers
01.09.11 10
01.10.11 20
01.11.11 30
01.12.11 40
Now what I want is in another cell: Get the number of the date, where the date's month is the current month. How do I do this?
Assuming all your dates are strings of the form "dd.mm.yy", you can use the following array formula:
=INDEX(B1:B4,MATCH(9,VALUE(MID(A1:A4,4,2)),0))
where the 9 is the month number you want to look up. Enter this as an array formula by pressing Ctrl+Shift+Enter.
EDIT:
As pointed out in the comments, you want to match the current month, so incorporating #JMax's suggestion works:
=INDEX(B1:B4,MATCH(MONTH(TODAY()),VALUE(MID(A1:A4,4,2)),0))
To clear up any confusion, MID() returns a string, which by itself will not return a match for the number value returned by MONTH(TODAY()). However, if you stick the MID() function inside a VALUE() function, the string returned by MID() will be converted into a number value. E.g., "09" becomes the number 9, "10" becomes the number 10. This allows you to match the number value returned by MONTH(TODAY()).
However, if your dates are entered as dates with format dd.mm.yy in your sheet instead of as strings, then you can use the same strategy but with a different matching term:
=INDEX(B1:B4,MATCH(MONTH(TODAY()),MONTH(A1:A4),0))
Enter this as an array formula.

Resources