Number Format

A

AHopper

I want to format a variable number before or as I store
it.
The variable is
Dim NewCartonWeight As Single

I store the number by using the following:

Set CurDb = CurrentDb
Set RegisteredUnique = CurDb.OpenRecordset
("tblRegisteredAndUniqueLabels")
With RegisteredUnique
.AddNew
!CartonWeight = NewCartonWeight
.Update
End With
RegisteredUnique.Close
Set RegisteredUnique = Nothing
(I did not include all the fields that make up the new
record)

The record stores as it should, however, I get a number
like 10.1999998092651 I want to store it with two decimal
places like 10.10.

At what point can I format the number?
How do I format the number?

Thank you in advance for your help.

Allan
 
G

Guest

hi,
access is a little squirrelly with the numbers sometimes.
you have format the table you data is in. open the table
in design mode. set decimal paces for all number type
fields. default is auto.
 
A

AHopper

I thought there was something I could do with format. But
I don't know how to make the decimal places.

Format (NewCartonWeight)
Allan
 
A

Allen Browne

Computers cannot store floating point numbers precisely. If it is important
for Access to remember and display precisely 2 decimal places, use the fixed
point number type - Currency.

1. Open your table in design view.
2. Select the CartonWeight field.
3. Change its Data Type to Currency.
4. In the lower pane set these properties:
Format Fixed
Decimal Places 2

It is possible to apply that formatting without changing the data type to
Single. Access will then display it correctly until you enter the field, but
then it will show the entire thing as stored. The Currency type will store
and display up to 4 decimal places exactly as you entered them.
 
A

AHopper

Allen
Thank you very much for your help.

Allan
-----Original Message-----
Computers cannot store floating point numbers precisely. If it is important
for Access to remember and display precisely 2 decimal places, use the fixed
point number type - Currency.

1. Open your table in design view.
2. Select the CartonWeight field.
3. Change its Data Type to Currency.
4. In the lower pane set these properties:
Format Fixed
Decimal Places 2

It is possible to apply that formatting without changing the data type to
Single. Access will then display it correctly until you enter the field, but
then it will show the entire thing as stored. The Currency type will store
and display up to 4 decimal places exactly as you entered them.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 

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