Solved

How to return unrounded number

Posted on 2014-09-18
3
343 Views
Last Modified: 2014-09-20
In MS Access vba code I want to return an unrounded version of a number trunctated to a specified number of decimal places.

For example, I  have a number of   131.2999999998

I want to truncate this number to 3 decimal places and end up with 131.299,  NOT 131.3
How do I do that?
0
Comment
Question by:dsoderstrom
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
?formatnumber(131.2999999998,3)
131.300

?format(131.2999999998,"#.000")
131.300

if you want to not roundup the values

?int(131.2999999998) + mid(cstr(131.2999999998),instr(cstr(131.2999999998),"."),4)
 131.299
0
 

Author Closing Comment

by:dsoderstrom
Comment Utility
Thanks for the help and the quick reply
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Just in case anyone should happen to look up this post:

That is really the most clumsy rounding "method", I've ever seen. And it fails in an international environment.
Numbers should always be handled like numbers.

Here is how to do this:

dblNumber = 131.2999999998
lngNumber = Int(dblNumber * 1000) / 1000

Returns 131.299

/gustav
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now