excel forumal round off the values - excel-formula

In excel formula I am in need to round off the values. So my query is how I can set the function if 4th decimal value greater than or equal to 5 means I need to round off the 3rd value. This is what my query.

Set the cell A1 to 1.23456789
Set A2 to "=ROUND(A1,3)"
A2's value shows as "1.235"
The round function takes as the first parameter, the number you wish to round off. The second parameter is the number of decimal places to keep before the rounded slot. So, you want the decision to be made off the 4th decimal, set the second parameter to 3.
EDIT (due to comment) :
So, check the 4th decimal place and if >= 5 round at 3rd place, else don't touch value at all?
If the number is A.BCDEFGHIJ... then if E >= 5, return A.BCD or D+1 if we round up, or if E<5 return full number A.BCDEFGHIJ...
=IF((MOD(A1*10000,10)>=5),ROUND(A1,3),A1)
So, if A1 = 1.23456789, then the answer is 1.235 but if A1 = 1.23446789, then the answer is 1.23446789
How it works :
I take A1 and multiply by 10000 to make the 4th digit to the left of the decimal, then modulus with 10, to remove all other digits and then check that digit against a value of 5. If >=5, we round off at the 3rd decimal place, otherwise, we return the full number.

Related

Get random value in the range of plus/minus 10% of a cell value in Excel

I have a column with positive numbers and want to calculate for each of them a random value, which is however placed in the range of 10%, so the calculated value is maximally 10% lower or higher as the original value.
The second requirement is - the result must be higher then zero.
I tried a formula like the following - but it seems to be wrong, because of not matching the second requirement, i get sometimes values lower then zero.
=IF(RAND()<0.5,(B2+(B2/100)*90)-(RANDBETWEEN(B2-0.1,B2+0.1)),(B2-(B2/100)*90)+(RANDBETWEEN(B2-0.1,B2+0.1)))
If you are only dealing with integers and your value is in B2, why not just use RANDBETWEEN(B2*0.9, B2*1.1). If B2 is positive, this cannot return a negative number since 0.9 * a positive number will still be positive.
If you want to have floating point numbers, you can use RAND() to generate a random number between 0 and 1, then subtract 0.5 and divide by 5 to get a number between -0.1 and 0.1. Then you can add 1 and multiply that by the original value to get something between 0.9 and 1.1 times it:
=(1+(RAND()-0.5)/5)*B2

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.

Difference between 2 values in a row in excel formula

How to get this in excel
excel table
F column is the result column
For the following answer I am going to assume you only ever have two numbers in any row, but they can be in any cell along the row and they are always greater than 0.
If you just wish to find the difference between the two numbers without worrying about which number is bigger, a simple equation using maximum and minimum can be used, eg in Cell F1 you would have
=MAX(A1:E1)-MIN(A1:E1)
However, from your example, it seems more likely that you want to know the difference between the first number and the second number.
The difficulty here, is that the cells in columns B, C and D could contain either the first number, the second number, or no number! The solution is to use the following equation in Cell F1
=(MAX(A1:E1)-MIN(A1:E1))*IF(MAX(A1:E1)=INDEX(A1:E1,MATCH(0,A1:E1,-1)),-1,1)
This formula works as follows:
We still start off with the simple difference between the max and min, and then this is multiplied by 1 or -1 depending on which way around the numbers are.
MATCH(0,A1:E1,-1)
This part of the equation looks along the row for a 0, and assumes they are in descending order, so it will return the position of the second number.
This is then inserted into the INDEX function and checked to see if it is the same as the maximum number and the IF function returns either -1 or 1 as required.
Paste this formula on F1, then copy to F2 and F3
=INDEX(A1:E1,MATCH(TRUE,INDEX(A1:E1<>"",),0)) - LOOKUP(9.99E+307,A1:E1)

How to round decimal values for specific rule

I want to use a rule in excel for specific values.
If price>=8.40 then price should be 8.99 and if price<8.40 then price is 7.99. Meaning if decimal value is >=40 then it should be .99 with same starting digit but if decimal value is <.40 then it should be starting value -1 and then .99. Sorry if i am unable to explain my requirement. Some examples are given below.
Present price New Price
8.40 8.99
8.39 7.99
8.41 8.99
8.25 7.99
Try this one:
=ROUND(A1+0.1,0)-0.01
Suppose the Present Price values reside in 'A' column, add the worksheet formula shown above in New Price Columns' first cell (e.g. B1) and expand it to the end of populated range.
Note: regular Excel Round() to Integer worksheet Function typically uses value of 0.5 as a threshold for rounding up (otherwise it will round down to the nearest Integer). So, just increasing the value by 0.1 should suffice your task).
Hope this will help. Rgds,

Rounding cell value to nearest thousand in excel

I have been trying to round a cell value up or down to the nearest thousand but can't get it to work. I'm trying to calculate my hourly rate based on the current exchange rate from USD to VND But if the resulting total is something like 22,325 then it should round down to 22,000 and likewise if the hundreds are 500 or more it should round up to 23,000
So where the hourly rate says 527,325 it should round down to 527,000. The cell already contains a formula to multiply the the current exchange rate by the USD.
Using the ROUND function:
=ROUND(A1,-3)
Where A1 is the cell containing the number you wish to round.
The negative number specifies digits to the left of the decimal point to replace with zeros (the number of zeros at the end of the number).
Like so:
=ROUND( 34528, -3 ) = 35000
As for the OP's example:
=ROUND( 22325, -3 ) = 22000
The OP also stated:
likewise if the hundreds are 500 or more it should round up to 23,000
=ROUND( 22500, -3 ) = 23000
See ROUND Function Office support
You can also try this:
=MROUND(A1,1000)
This should give you what you want.
You've asked specifically for a formula that when it 'says 527,325 it should round down to 527,000'. For this you would need the FLOOR¹ function or ROUNDDOWN¹ function.
=FLOOR(A1, 1000)
=ROUNDDOWN(A1, -3)
There is also leaving the number alone but formatting with a custom number format of 0, K but this does not round down. If the number was 527,501 it would display 528 K not 527 K.
      
¹ The counterparts to FLOOR and ROUNDDOWN are the CEILING function and ROUNDUP function.
Divide by 1000, then round, then multiply by 1000.
The formula for rounding A1 in this way would be:
=ROUND(A1/1000)*1000
If a formula already exists in the A1 cell, just replace the A1 with the new formula in the upper expression.

Resources