counting decimal places


J

JohnE

I have a subform on a main form. In the subform the user will be entering
decimal numbers for precision testing. The backend sql server table is
allowing for 4 decimal places (ex 10.0001). The users may not always enter 4
decimal places depending on the instrument and the degree of precision
needed. So, a user could enter 1.01 or .015 or .0001, as examples. But the
backend sql server table will add a zero to complete the empty decimal place,
if necessary. For a Mech Eng there is a difference between .001 and .0010.
So another field is there to record the number of decimal places that the
user typed in. The field is hidden on the subform (continuous) to record the
count. My thought was to put in the afterupdate of the field they type the
info in. How do I make a count such as that?
Thanks.
.... John
 
Ad

Advertisements

K

KARL DEWEY

Try opening the subform in design view and set the property of Decimal Places
to Auto and the Format as blank.
 
J

JohnE

Thanks for the reply but I think you might misinterpreted. I need the count
of how many decimal places the user typed in.
1.001 --> 3
..0015 --> 4
..01 --> 2
10.1 --> 1

and so on. I need to record the 3, 4, 2, 1 numbers.
 
J

JohnE

This is what I have sofar but stuck on count just to the right of the decimal
point.

Dim decCount As Long
decCount = Len(UpperTolerance)
SignificantDigits.Value = decCount
 
J

JohnE

It think I got it. I used the following.

Len(right(Trim([UpperTolerance]), Len(Trim([UpperTolerance])) - InStr(1,
[UpperTolerance], ".")))

Thanks.
 
K

KARL DEWEY

What I posted was so that your form would display correctly rather than have
trailing zeros.
 
Ad

Advertisements

J

JohnE

The trailing zeros need to show. Actually, all the numbers need to show. As
mentioned, to a mechanical engineer doing precision tolerance testing on
medical devices there is a difference in .001 and .0010 depending on the
device and the precision testing. This info is needed for documentation when
FDA or other medical entities perform audits. If an auditor looked at the
documentation for a device and it showed .0010 it would infere that the
precision measure testing went out 4 decimal places. Which would provide
false documentation if the precision testing actually was 3 decimal places.
The most done here goes to 4 decimal places on some device testing while
other devices only require 3 places of testing precision. That is why I need
the actual count of decimal places as the db is set to 4 places and all
precision tolerance testing goes into the table.
Just wanted to let you know the reason for the need of the count.
 
J

Jack Leach

I think you can use the Split function to do this as well.

Dim x
x = Len(Ubound(Split(Trim(Str(YourNumber, ".")))))


This should convert your number to a string, trim and spaces, split it into
an array with two values (left of decimal and right of decimal), and read the
Length of the uppermost element of the array, which should be the number of
decimals that will correspond to your tolerance block.


--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



JohnE said:
It think I got it. I used the following.

Len(right(Trim([UpperTolerance]), Len(Trim([UpperTolerance])) - InStr(1,
[UpperTolerance], ".")))

Thanks.


KARL DEWEY said:
Try opening the subform in design view and set the property of Decimal Places
to Auto and the Format as blank.
 
Ad

Advertisements

K

KARL DEWEY

I do not think that will work as I have not heard of a number field storing
either leading or trailing zeros. A text field can though, but I would use
Len(Mid([YourField], InStr([YourField], ".")+1))

Maybe you could capture the data entry somehow with the Before Update event
to measure prior to the key strokes being entered into a number field.

--
Build a little, test a little.


Jack Leach said:
I think you can use the Split function to do this as well.

Dim x
x = Len(Ubound(Split(Trim(Str(YourNumber, ".")))))


This should convert your number to a string, trim and spaces, split it into
an array with two values (left of decimal and right of decimal), and read the
Length of the uppermost element of the array, which should be the number of
decimals that will correspond to your tolerance block.


--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



JohnE said:
It think I got it. I used the following.

Len(right(Trim([UpperTolerance]), Len(Trim([UpperTolerance])) - InStr(1,
[UpperTolerance], ".")))

Thanks.


KARL DEWEY said:
Try opening the subform in design view and set the property of Decimal Places
to Auto and the Format as blank.
--
Build a little, test a little.


:

I have a subform on a main form. In the subform the user will be entering
decimal numbers for precision testing. The backend sql server table is
allowing for 4 decimal places (ex 10.0001). The users may not always enter 4
decimal places depending on the instrument and the degree of precision
needed. So, a user could enter 1.01 or .015 or .0001, as examples. But the
backend sql server table will add a zero to complete the empty decimal place,
if necessary. For a Mech Eng there is a difference between .001 and .0010.
So another field is there to record the number of decimal places that the
user typed in. The field is hidden on the subform (continuous) to record the
count. My thought was to put in the afterupdate of the field they type the
info in. How do I make a count such as that?
Thanks.
... John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top