Solved

Rounding results of a division to 2 decimal places

Posted on 2004-09-09
4
213 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
[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
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
rcmb earned 100 total points
ID: 12020477
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
ID: 12021289
Thanks very much rcmb for prompt reponse!  Jeeva
0
 
LVL 12

Expert Comment

by:rcmb
ID: 12023570
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
ID: 12027213
Yes, that's much neater.  Thanks again.   Jeeva
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

688 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