Solved

Rounding results of a division to 2 decimal places

Posted on 2004-09-09
4
207 Views
Last Modified: 2013-12-24
Rounding results of a division to 2 decimal places

I have the following lines of code in the body section of a web page which is displaying data from a database using the DateBase Results Wizard:-

<%
varDisplayAcres = fp_rs("plotarea")
varDisplayAcres = varDisplayAcres/4047
%>

I am wanting to display a plot area of land which is on an Access database in square metres, also as acres.  This involves dividing by 4047 as a good enough approximation.  I need the results to be displayed to only 2 decimal places

Here is an example of what I am having displayed at the moment:-

Plot area (sq.m.) = 590.   Acres = approx 0.145787002718063

I want the acres to be shown as 0.15 for preference, although simple truncation to 3 decimal places, i.e. as 0.145 would be acceptable.

This is I am sure simple, but I am without any textbooks/manuals where I am working at the moment.

(I know how to do this using an Access query with the calculation and the acres embedded within the Access query, but in this case I want to do the calculation outside of Access, and within the displaying web page).

Thanks for assistance.
0
Comment
Question by:Jeeva
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
rcmb earned 100 total points
Comment Utility
Change your code to read as follows:

<%
varDisplayAcres = fp_rs("plotarea")
varDisplayAcres = varDisplayAcres/4047
varDisplayAcres = formatnumber(varDisplayAcres,2)
%>

where ,2 gives you the number of decimal places to show.

RCMB
0
 

Author Comment

by:Jeeva
Comment Utility
Thanks very much rcmb for prompt reponse!  Jeeva
0
 
LVL 12

Expert Comment

by:rcmb
Comment Utility
You are welcome -- just as a side note you should be able to shorten this whole process by entering this:

<%= formatnumber((fp_rs("plotarea")/4047),2)%>

RCMB
0
 

Author Comment

by:Jeeva
Comment Utility
Yes, that's much neater.  Thanks again.   Jeeva
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

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

10 Experts available now in Live!

Get 1:1 Help Now