Convert decimal to whole number - but ignoring value - excel

I know how to isolate the decimal using the TRUNC() function, as well as taking the original value and subtracting this truncated part.
And I can then multiply to get whole number.
But that only works if all my decimals are the same place. I want something that will get me the amount after the decimal point as a whole number, regardless of how many places.
eg: 12.2 would return 2
12.21 would return 21

With data in A1, consider:
=IF(ISERROR(FIND(".",A1)),A1,--MID(A1,(FIND(".",A1)+1),9999))
Naturally leading zeros in the output are dropped:

Related

How to maintain leading zeroes on binary conversions in Excel

I want to convert a series of numbers < 1000 into binary to do some bitwise analysis in Excel
But the DEC2BIN function in Excel doesn't seem to allow me to specify leading zeroes for the smaller numbers. The BASE(x,2) functionn will handle the larger numvbers better than DEC2BIN, but still drops leading zeroes of the smaller numbers.
=BASE(999,2) returns 1111100111 but =BASE(511,2) returns 111111111
I would really like it to return 0111111111
Is it possible to do that in Excel?
You can just specify the minimum number of digits when using Base e.g.
=BASE(511,2,10)
Since your numbers are all less than 1000, 10 digits are sufficient.

Excel: number entered vs number displayed vs number stored in memory

How does excel determine what to number to display? specifically the number of decimal places
for example:
50.98, when stored as a single-precision float is 50.979999542236328125
50.979999 is also stored as the exact same single-precision float
(binary rep. 01000010010010111110101110000101, taken from here: https://www.h-schmidt.net/FloatConverter/IEEE754.html)
when i type 50.98 & 50.979999 into 2 cells, change format to number, and extend out the decimal places using the formatting button
it represents them exactly as 50.98 & 50.979999, as i originally typed.
how is that working? is excel storing the exact text i typed and not (directly) storing the float data type at all?
if it stores it as a double, how does it preserve the exact precision i originally typed in that case?
i can't find documentation outlining how this works.
Note its not causing me any problems, i just need an explanation for differences in how excel displays vs calculations based on those values.
it represents them exactly as 50.98 & 50.979999, as i originally typed.
Excel is padding with zeros after 15 significant decimal digits.
The internal number is encoded with a high enough binary precision such that limiting output to 15 deimcal places, the original typed in decimal values appear to be exactly that.
=2/3 is an informative example showing this limit and exposing the binary internals by carefully extracting out a bit at a time.
As displayed in one cell, decimal output rounds to 15 places, padding with zero after that.
0.66666666666666700000000
The below does a binary conversion of =2/3 and forms 0.101010101010101010101010101010101010101010101010101012, exactly what is expected if Excel used a binary64. (Below)
OP's observations are consistent with using binary64 and rounding output as decimal text to 15 significant digits.
Cell A3: =FLOOR(B2*A$1,1), Cell B3 = =B2*A$1 - A3
Hypothesis: When displaying a number, Excel first converts a number to a decimal numeral with at most 15 significant digits even if more are requested. If additional digits are requested, they are filled in as zeros. (In addition, Excel may apply other alterations depending on context.)
In Microsoft Excel 2008 for Mac, I entered =1+22*POWER(2,-52) in A1 and =1+23*POWER(2,-52) in A2. Using IEEE-754 binary64, these should generate the numbers 1.000000000000004884981308350688777863979339599609375 and 1.0000000000000051070259132757200859487056732177734375. Entering =A1-1 and =A2-1 in B1 and B2 and setting these to Number format with 30 decimal places shows “0.000000000000004884981308350690” and “0.000000000000005107025913275720”, which is consistent with IEEE-754 binary64. So we have some assurance the numbers above were indeed generated and stored in Excel.
Setting A1 and A2 to Number format with 20 decimal places shows “1.00000000000000000000” and “1.00000000000001000000”.
Clearly, if Excel were displaying the actual numbers with 20 decimal places, it would show “1.000000000000004885” and “1.000000000000005107”. It does not. The display we see is consistent with converting the numbers using 15 decimal digits (significant digits, not just those after the decimal point) and then padding with zeros.
Converting 50.98 to the IEEE-754 binary64 format yields 50.97999999999999687361196265555918216705322265625. Displaying this with 15 decimal digits yields 50.9800000000000.

Function that returns number of significant figures after decimal point in specific formatting

Wondering if anyone knows a function that would return the number of significant figures after a decimal point? And even further how to put that number in a specific formatting?
For example if the number was 27.9834 it would return 0.0001. Or if it was 2.1 it would return 0.1.
You should be able to do this using a LEN and MATCH to get the number of decimal points, then its a simple "^" function to get the decimal place.
Assuming your number is in Cell A1:
=10^-(LEN(A1) - FIND(".",A1))
Just make sure you are showing the right number of significant digits in the result cell or it will just look like zero.
The LEN() counts the number of characters and then you subtract the number of characters from the left to where the decimal is. I think there is an upper limit on the number of decimals that excel can handle, but i don't recall what it is.
Another method might be,
=AGGREGATE(14, 6, POWER(10, -(ROW($1:$16)-1))/(TRUNC(A2, ROW($1:$16)-1)=A2), 1)

Numbers stored as text - when converted to numbers, digits disappear

I have a column of data with numbers stored in text.
The numbers look like this: 735999114002665788
If I select any cell in this column and refer to it with the function =value(), the number shows up as 735999114002665000.
As you can see the last three digits are 0. This happens all the time with numbers this long - but NOT with numbers containing less digits.
Am I trying to convert a number that's too large or what's up? Please help! I've tried every form of text-to-number method with identical results :(
Excel's number precision is 15 digits, which is why you're losing the last three digits when converting your 18 character string
https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3#ID0EBABAAA=Excel_2016-2013
Excel only allows a maximum of 15 digits of precision for each number in a cell. The reason why this number:
735999114002665788
becomes this:
735999114002665000
is because Excel is choosing to retain the 15 most significant digits in the number. This means that the ones, tens, and thousands digits are being tossed out.
By the way, this question has been asked before on SuperUser, and you can read about it here:
https://superuser.com/questions/437764/why-is-excel-truncating-my-16-digit-numbers

How to round a value In Excel

I want to round off the value in Excel when the value is greater than 5 after decimal.
For example:
if num= 9.15, result= 9.1
if num= 9.16, result = 9.2
Although your need contradicts the currently valid rounding rules it could be achieved with the following formula:
=TRUNC($A1*10^1+0.4*SIGN($A1))/10^1
The value in A1 can be any decimal value in any length either positive or negative. It will be "rounded" to 1 decimal place. The 10^1 part in the formula leads to rounding to 1 decimal place. Use 10^2 to round to 2 decimal places and so on.
For the second decimal place, I was going to post
=IF(AND(FIND(".",A2&".")=(LEN(A2)-2),RIGHT(A2)="5"),--LEFT(A2,LEN(A2)-1),ROUND(A2,1))
(modified according to #Jasen's comment)
A very simple approach is
=ROUND(A4-10^-10*SIGN(A4),1)
which should be fine up to several places of decimals if you change the number of decimals to round (but will fail because of rounding errors if the numbers are too large).
This also gives good results over a wide range of numbers:-
=ROUND(A2-A2/10^12,1)
To generalise the first one a bit more you could try
=IF(ISNUMBER(FIND(".",A2)),IF(RIGHT(A2)="5",--LEFT(A2,LEN(A2)-1),ROUND(A2,LEN(A2)-FIND(".",A2)-1)),A2)
to round the last decimal place down if it's a 5.
this should do it
=ceil(A1*10-0.5)/10

Resources