By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

get number of digits

P: 68
I need to get the number of digits in a variable number that may have anywhere from 3 to 6 digits. How do I find this?
Feb 7 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,545
Assuming that you are using an MS Access query and you are wanting to find the number of digits in a positive whole-number field, you can use the string function Len() to return the 'length' of the number as follows:

Expand|Select|Wrap|Line Numbers
  1. SELECT Len([Your Field Name Goes Here]) as Digits FROM YourTable;
Example of the use of Len() on the Inventory on Hold query of Northwind 2007:

Expand|Select|Wrap|Line Numbers
  1. Quantity On Hold  Digits
  2.         25        2
  3.         23        2
  4.        325        3
  5.        110        3
  6.         20        2
  7.         75        2
The SQL for this is just

Expand|Select|Wrap|Line Numbers
  1. SELECT [Quantity On Hold], Len([Quantity On Hold]) AS Digits
  2. FROM [Inventory on Hold];
Feb 7 '12 #2

P: 68
Thanks for your reply! I figured out to use the Length function after posting the question.
Feb 7 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.