Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Checking the number of decimal numbers

Posted on 2006-06-24
Medium Priority
166 Views
Hi, I have a MSAccess application with VB code behind it, how do I check how many decimal numbers a numeric variable holds?

I tought I could multiply by 10/100/1000, remove the integer part and see if it's still higher than 0 - but how do I pick only the integer part of a number?
0
Question by:Emanuele_Ciriachi
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 93

Accepted Solution

Patrick Matthews earned 512 total points
ID: 16976014
Hi Emanuele_Ciriachi,

I assume that you mean, if the variable currently holds the value 123.4567, you would want 4, which is the number of
characters to the right of the decimal point.

If this is so, try this UDF:

Function DecimalPlaces(OrigNumber As Variant)

Dim arr As Variant
Dim TestStr As String
Dim TestLen As Long

TestStr = CStr(OrigNumber)
arr = Split(TestStr, ".")

On Error Resume Next

TestLen = Len(arr(1))

If Err <> 0 Then TestLen = 0

DecimalPlaces = TestLen

End Function

There are alternative approaches, such as:

Len(MyNumber - Int(MyNumber)) - 2

but I advise against this: a floating point operations like this can lead to an apparent inflation of the number of
decimal places.  That is why I immediately converted the numeric value to a string.

Regards,

Patrick
0

LVL 1

Author Comment

ID: 16976102
Works like a charm. Thanks.
0

LVL 93

Expert Comment

ID: 16976509
Emanuele_Ciriachi,

You're most welcome :)

Regards,

Patrick
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month9 days, 14 hours left to enroll