Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

Formating # of decimal places displayed in Textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BRC - 14 Jul 2007 05:55 GMT
using access 2003 and Win xp pro
I have a problem with formatting a form textbox to display the the
correct number of decimals.  The text box is a calculated field that
is [grams_unit] * [quanity].  Grams_unit is in a table as field size:
"single", format: "general number", decimal places: "2".  In the table
the grams_unit displays as .85.  However when I do the calculation for
my textbox (totalgramsTB)  1*grams_unit yields 0.850000023841858 and
it displays 15 decimal places. What I would like is for it to display
only .85.  I have no idea where all these numbers are coming from. I
don't want to set the format to fixed because I don't want it to
appear to be currency. Any suggestions would be appreciated. As
always, thanks for any help
BRC
Allen Browne - 14 Jul 2007 06:51 GMT
Okay, this is typical of floating point calculations.

You may be able to help the display by explicitly rounding, i.e. change the
calculation from:
   [grams_unit] * [quanity]
to:
   Round([grams_unit] * [quanity], 2)

However, the floating point error will still be present. An alternative
approach would be to use a fixed point number, such as Currency. By forcing
the calcuation results to this type, you avoid the floating point problems.
By default, Access will show the result as dollars and cents (or whatever
your currency is), butyou can circumvent that by setting the Format property
of your text box to Fixed. The calcuation would be:
   CCur(Nz(Round([grams_unit] * [quanity], 2),0))

For info on why floating point numbers cannot accurately represent real
numbers, see:
   http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> using access 2003 and Win xp pro
> I have a problem with formatting a form textbox to display the the
[quoted text clipped - 9 lines]
> always, thanks for any help
> BRC
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.