Percent field folly

B

Bill Sturdevant

I am trying to define a field as a percent. I read that
when you enter a number, it gets multiplied by 100 and
displayed as a percent.

So, entering "25" gets stored and displayed as 2500%

But, I do not want the value to be twenty-five hundred
percent, I want the value to be twenty-five percent.

So, I enter .25 and get 0%, apparently because of rounding.

From a user perspective, both of these are crazy.

How do I set things up so the user enters "25" and
immediately sees "25%" in the field?
 
M

Marshall Smith

What is the Data Type and Field Size of the field? The Data Type should be
Number, and the Field Size should be Single. If the Field Size is still set
to Long Integer, you won't be able to enter fractions (and, hence, won't be
able to enter percentages).

My solution, which I think is inelegant but I haven't worked out a better
one, is to put code in the AfterUpdate event of the appropriate text box on
the form to immediately divide what was entered by 100. That makes the user
happy, and keeps everything working right.

HTH,

Marshall Smith
Project Developers, Inc.
 
T

Tim Ferguson

So, I enter .25 and get 0%, apparently because of rounding.

From a user perspective, both of these are crazy.

How do I set things up so the user enters "25" and
immediately sees "25%" in the field?

I just answered a similar question above. The rounding is because you are
using an integer field: change it to a Double or Single.

The value stored _is_ a fraction: if you want a quarter, then the value is
0.25 and it is displayed as 25%. That is not crazy, it is first-grade
maths. If you want the user to enter 25, then frankly that is what I would
store in the field. It is easy to place a "%" character on the form to
remind everyone what it means. When it comes to calculating, it is easy to
remember to divide by 100 again, just like any other units conversion.

currTotalCost = FinalPrice * (1.0 + TaxPC / 100.0)

Hope that helps


Tim F
 

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