Written by Allen Wyatt (last updated October 12, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Ashley wonders how to limit the input of a number to 2 decimal places. In trying to figure it out, she notes that the Data Validation tool does not seem to work for this requirement.
There are two ways you can approach this problem. The first is to use a custom rule in Excel's Data Validation tool. Follow these steps:
Figure 1. The Settings tab of the Data Validation dialog box.
=MOD(A1*100,1)=0
This validation formula works because it checks to make sure that the value in A1, when multiplied by 100 and then divided by 1, has no remainder. It will only have this remainder if there are three or more decimal places in the value entered. Validation will also fail if someone tries to enter text into cell A1.
There are, of course, any number of other formulas you could use in step 6. Here are a few:
=INT(A1*100)=(A1*100) =A1=ROUND(A1,2) =ABS(A1-ROUND(A1,2))<1E-8 =FIND(".",A1,1)>=LEN(A1)-2
Instead of using Data Validation, there is another approach you could take. This one involves using the following steps:
Figure 2. The Advanced options of the Excel Options dialog box.
Now, when someone enters a value into the cell you formatted in step 2, it will be rounded to two decimal places automatically, and Excel will make sure that any calculations use the two-decimal-place value.
The drawback to this approach is that changing how Excel does its calculations (steps 3 through 6) affects the entire workbook, not just the data-entry cell selected in step 1. If this is unacceptable to you, then you should definitely choose the Data Validation approach, discussed earlier.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (889) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Drop-down lists are handy in an Excel worksheet, and you they can be even more handy if a selection in one drop-down ...
Discover MoreIf you want to make sure that only unique values are entered in a particular column, you can use the data validation ...
Discover MoreWant to have a small help screen pop up when a user selects a particular cell? This can be done by using data validation, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-08-16 05:52:44
uk
data validation not working on data pasted in cells .
E.g. i have applied data validation for 2 decimal values. but it allows any decimals in same cell when data are pasted using paste special value function. the validation works absolutely fine when data are entered manually.
2021-06-14 15:07:41
Hi,
MOD(A1*100,1)=0 works but when entering 130.11 it doesn't. Why could that be?
2021-02-12 11:08:00
Bill
I have also found that the MOD() method results in multiple errors. I was certain that it had to do with the second part of my validation which compares values. But it was MOD()! I ran a check of 96193 cells and errors occurred 9175 times (a nearly 10% rate). It does not seem to be precision related, but I'm not absolutely certain about that as I did Fill-Down the 0.01, 0.02, 0.03...values (not hard entries). An expansion of displayed decimal places in the Error cells to the maximum (30) did not show any "higher" or "lower" values. It was formatted as Accounting and I did not try other formats to see if it replicated, though.
Changed my formula to MOD(INT($A1*100),1)=0 and it shows no errors over that range. Of course, Allen provides multiple formulas to achieve the desired result, so no complaints and Thank You!, but MOD() seemed the most straight-forward and the logic and math, seemingly, should work properly.
2021-02-03 04:04:16
VM
The fomula with =MOD(A1*100,1)=0, will result in ERROR with certain numbers. By accident I happened to fill in 0.28 (max. 2 decimals) and it was not allowed. Curious to know, I check all numbers between 0.01 - 10.00 (=1000 tests) and I found 72 numbers with a mistake up to 5.11 and upwards of 6.24 ALL where not ok.
2020-08-13 10:04:47
Sushi
I have rounded off my data to 2 decimal places still when my excel is getting data from tables, it is diplaying the data upto 20 decimal places.Even after setting the precision as diplayed , unable to achieve the requirement of showing data upto 2 decimal places. Can u suggest something.
2019-07-17 13:36:06
John Lute
I'm finding this very helpful - thanks! I'm having trouble with =FIND(".",A1,1)>=LEN(A1)-2
I've modified this to =FIND(".",A1,1)>=LEN(A1)-4 in order to limit to four decimal places. The trouble with EITHER of these is that whole numbers won't match the validation. For example, 523.00 or 523.000 throw validation errors.
Any idea how to handle these?
2019-07-17 12:29:08
John Lute
I'm finding this very helpful - thanks! I'm having trouble with =FIND(".",A1,1)>=LEN(A1)-2
I've modified this to =FIND(".",A1,1)>=LEN(A1)-4 in order to limit to four decimal places. The trouble with EITHER of these is that whole numbers won't match the validation. For example, 523.00 or 523.000 throw validation errors.
Any idea how to handle these?
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments