Solved

How to return unrounded number

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

895 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

14 Experts available now in Live!

Get 1:1 Help Now