Solved

How to return unrounded number

Posted on 2014-09-18
3
365 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40330311
?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
ID: 40330363
Thanks for the help and the quick reply
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40334114
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

856 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