Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to return unrounded number

Posted on 2014-09-18
3
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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 51

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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