Excel formula for count numbers of decimals - excel

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.

Related

How to find the position of the last non-zero value of a decimal in a cell in Excel

I have the following 4 rows and I wish to find the decimal length (aka scale) of that decimal value. Do note that I'm importing all of the decimal data in Excel whose cell is formatted in a "Text" format (hence the trailing zeros even after the decimal values). And I do not want to convert it into decimal. I just need to find the scale of that decimal number.
Decimal Number
Scale (Formula?)
106.520000
2
0.080100
4
15.000010
5
265.000000
0
Been struggling for a very long time now. I'd appreciate any lead on this.
This is what I have tried,
• Formula used in cell B2
=LEN(MID(NUMBERVALUE(A2),FIND(".",A2)+1,255))
You could try:
Formula in B2:
=MAX(LEN(-A2)-LEN(INT(A2))-2,0)
Note: I use a decimal comma but it shouldnt matter for you.

Timevalue function not working for unrecognized time format

I have a bunch of time data that's formated weirdly, ranging from numbers 100 (representing 1 AM, or 01.00.00) to 2359 (representing 11.59PM, or 23.59.00).
I have been trying to use the TIMEVALUE() function to convert these data, but it just returns #Value?, I guess because the time format 'HHMM' is not recognized without the ' : ' separating them?
What I'd like is to convert it to the HH:MM:SS format, where the SS would automatically be zero.
Use REPLACE:
=--REPLACE(A1,LEN(A1)-1,0,":")
Then format it as desired.
If your text values are consistent, this can be carried out by using a formula that splits the value by the number of characters and then recombines the split values into a time value.
All formulas assume that your weirdly formatted text value is in cell B2
=IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1))
This formula works out the first (hour) element of a time, if the text string is greater than three characters it will take the first 2 characters of the string (23), if its less than 3 characters it will only take the first character (1)
=RIGHT(B2,2)
This formula takes the second (minute) element of the time.
=TIME(C2,D2,0)
Finally this formula converts the two text elements into a string
C2 = The cell with formula 1 in it
D2 = The cell with formula 2 in it
This could all be written as the following formula if needed
=TIME(IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1)),RIGHT(B2,2),0)

Bond Price fraction convert to decimal 32nd excel formula

i am pretty sure a lot of people in capital market experience this :
use excel formular to convert fraction to decial in 32nd
i know most case we just divide last 2 digits decimal place by 32 for example:
100-160= 100+16/32=100.5
100-200=100+20/32=100.625
but if 3 decimal places : 99-226=99+(22+6/8)/32=99.7109375
how do we convert it to formula in excel , please help!!!!
Assuming a data setup like this where your Bond Prices are in column A and your formula for Decimal Conversion is in column B:
The formula in cell B2 and copied down is:
=LEFT(A2,FIND("-",A2)-1)+(MID(A2&"00",FIND("-",A2)+1,2)+MID(SUBSTITUTE(A2,"+",4)&"000",FIND("-",A2)+3,1)/8)/32
Alternative Using FilterXML() function
Adding a further column B with the following xml conversion
="<t><a>" &SUBSTITUTE(SUBSTITUTE(A2,"+","4"),"-","</a><b>")&"</b></t>"
you can calculate results in a next column via FilterXML() available in Excel 2013+:
=FILTERXML(B2,"//a")+(LEFT(TEXT(FILTERXML(B2,"//b"),"000"),2)+RIGHT(TEXT(FILTERXML(B2,"//b"),"000"),1)/8)/32
tl;tr - one column solution (just for fanatics)
Of course you could also force the xml base into one formula:
=FILTERXML("<t><a>" &SUBSTITUTE(SUBSTITUTE(A2,"+","4"),"-","</a><b>")&"</b></t>","//a") + (LEFT(TEXT(FILTERXML("<t><a>" &SUBSTITUTE(SUBSTITUTE(A2,"+","4"),"-","</a><b>")&"</b></t>","//b"),"000"),2)+RIGHT(TEXT(FILTERXML("<t><a>" &SUBSTITUTE(SUBSTITUTE(A2,"+","4"),"-","</a><b>")&"</b></t>","//b"),"000"),1)/8)/32

Excel Remove Decimal Places

I have an excel formula that is producing a lot of decimal places and I cannot reduce them using the format cell -> numbers -> decimal places options. Here is the formula.
Cell named V01_MIN
V01_MIN =MIN(6:6)
Has a value of 2
Cell named V01_MAX
V01_MAX =MAX(6:6)
Has a value of 1800
Cell named V01_A
V01_A =1-V01_MIN*V01_B
Has a value of 0.889877642
Cell named V01_B
V01_B =99/(V01_MAX-V01_MIN)
Has a value of 0.055061179
X6=723
X7=V01_A+V01_B*X6 (value of 40.69911012)
X8=1
X9=X7*X8 (value of 40.69911012)
X10=1
X11=X9*X10 (value of 40.69911012)
X13==CONCATENATE(X12,", ",X11)
The final results of X13 are:
V01, 1162, 40.6991101223582
I want them to be:
V01, 1162, 40.7
I'm trying to figure out how to make this happen. I've already tried changing the cell formatting on all of these cells (including the final cell) to one decimal palce and that didn't work.
Cell formatting and the actual number in the cell are two different things.
The cell formatting merely changes how the number is shown to you in the cell.
The actual number in the cell will still keep all precision of the number.
If you wish to have the last number rounded, consider this:
X13=CONCATENATE(X12,", ",ROUND(X11,1))
This will round the result in X11 to 1 decimal place before concatenating.
By concatenating you are changing your data to text instead of a number and the number formats won't effect it. Generally you have two options
Either round within you concatenate function
X13==CONCATENATE(X12,", ",roound(X11,1))
or change it back to a number (easiest way is multiply by 1): Note this won't work in your case since you are joining text strings and variables but is useful to be aware of.
X13==CONCATENATE(X12,", ",X11)*1
and then you can format based on decimal places.

how to add zeros after numbers to get a fix length in EXCEL

I have 3 numbers in excel.
A1. 498
A2. 899
A3. 5209
I want the numbers as the followings:
B1. 49800
B2. 89900
B3. 52090
I am still finding the solutions via online but most of the resource is discussing about leading zeros.
Please, could you kindly give me any ideas? Thanks.
I hope this formula may be of some use:
=A1 & REPT("0"; 5 - LEN(A1))
Thought this does not set the format of the cell itself (which I doubt can be done as you are changing the value of the cell by adding the zeros)
The formula only works if you are dealing with numbers as text, so you may need to convert them to text in the formula (TEXT(A1; "0") instead of A1)
you can do this one quite easily without VBA - using an IF and the very handy REPT function:
=IF(LEN(H13)<5,H13&REPT(0,5-LEN(H13)),H13)
Essentially - if the length is less than 5 - you repeat 0 up to the amount of times that its missing.
Seems like simple math to me. Essentially you want to shift left (base 10) a certain number of times. We can do this by:
Calculate the ceiling of the base-10 logarithm of the value to get it's "length"
Subtract the result from the target "length" of 5, this is the number of places we want to shift
Take 10 to this power and multiply back by the value.
In other words, where x represents the value in column A you want to transform:
In Excel, this would be expressed as:
=A1*POWER(10,(5-CEILING(LOG10(A1),1)))

Resources