473,569 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: problem with javascript in asp not rounding up..

Gazing into my crystal ball I observed =?Utf-8?B?R1ROMTcwNzc 3?=
<GT*******@disc ussions.microso ft.comwriting in
news:44******** *************** ***********@mic rosoft.com:

ASP has no knowledge of the client, this is a client side issue.
Followups set to comp.lang.javas cript.
Hi All,

I have a neat little script that calculates price based on quantity
without refreshing the page.. the script is -

<script type="text/javascript">
function OpenWin(url)
{
window.open(url ,'win','scrollb ars=1,status=0, resizable=
0,widt
h=200,height=26 5');
}
function btnCalculate_on click()
{
var numQty;
var adprice;

if (isNaN(document .frmClient.txtQ ty.value))
{
alert('Please enter a number for advert quantity.');
}
else
{
numQty = parseInt(docume nt.frmClient.tx tQty.value);
adprice = parseInt(docume nt.frmClient.ad price.value);

if((numQty >= 1) && (numQty <= 1)){
document.getEle mentById('divPr ice').innerHTML = '£' + adprice + '
+ VAT'; document.getEle mentById('maind ivPrice').inner HTML = '£' +
Math.round(100* (adprice * numQty))/100 + ' + VAT';
} else if((numQty >= 2) && (numQty <= 10)){
document.getEle mentById('divPr ice').innerHTML = '£' +
(Math.round(adp rice * numQty)*.95)/numQty + ' + VAT';
document.getEle mentById('maind ivPrice').inner HTML = '£' +
Math.round(adpr ice * numQty)*.95 + ' + VAT';
} else if((numQty >= 11) && (numQty <= 20)){
document.getEle mentById('divPr ice').innerHTML = '£' +
(Math.round(adp rice * numQty)*.85)/numQty + ' + VAT';
document.getEle mentById('maind ivPrice').inner HTML = '£' +
Math.round(adpr ice * numQty)*.85 + ' + VAT';
} else if((numQty >= 21) && (numQty <= 30)){
document.getEle mentById('divPr ice').innerHTML = '£' +
(Math.round(adp rice * numQty)*.75)/numQty + ' + VAT';
document.getEle mentById('maind ivPrice').inner HTML = '£' +
Math.round(adpr ice * numQty)*.75 + ' + VAT';
} else if((numQty >= 31) && (numQty <= 50)){
document.getEle mentById('divPr ice').innerHTML = '£' +
(Math.round(adp rice * numQty)*.5)/numQty + ' + VAT';
document.getEle mentById('maind ivPrice').inner HTML = '£' +
Math.round(adpr ice * numQty)*.5 + ' + VAT';
} else {
alert("Please contact us for more information about the benefits
of our
monthly account packages.");
}
}
}</script>

The problem I have is that it doesn't round up, for instance in stead
of £0.95 i get £0.94999999999 98.

Does anyone have any ideas how to fix this?

Many thanks


--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Aug 22 '08 #1
1 1339
In comp.lang.javas cript message <Xn************ *************** *@69.16.18
5.247>, Fri, 22 Aug 2008 13:01:23, Adrienne Boswell <ar****@yahoo.c om>
posted:
>The problem I have is that it doesn't round up, for instance in stead
of £0.95 i get £0.94999999999 98.

Does anyone have any ideas how to fix this?
You could try reading the FAQ of comp.lang.javas cript, and/or my site.

A programmer should know that binary floats can represent few simple
decimal fractions exactly.

If your results are hoped to be in pounds, with a 2-digit decimal
fraction part, then calculate in pence and insert the point as part of
output formatting.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Aug 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1520
by: Dr John Stockton | last post by:
When rounding (or truncating) a number which may be either positive or negative, it is sometimes necessary to round either towards plus infinity or towards minus infinity. But those are special cases. Normally, however, rounding should be symmetrical about zero; rounding X should give the same digits as rounding -X, for all X. Some of the...
16
2168
by: shekharpati | last post by:
hi all, I,m trying to read a space delimited file with the use of formated input through fscanf. But surprisingly i am able to read all the 4999 lines of data except the "first line" which is giving random output(i.e not present in the file). the code is given below(the relevant part). sample input from the data file 01 48554.73828 504...
35
2263
by: eyoung | last post by:
I call a function that takes the unit price and quantity ordered to create an amount...it looks something like this. function calculateCost() { quantity=document.RFO.quantity.value; unitPrice=document.RFO.unitPrice.value; total=0; if(isPositiveInteger(quantity)) {
19
3583
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm starting a new one] I'd still like to finish this rounding mess. As a startup lemma we can take that VK is the worst programmer of all times and...
28
5841
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is...
20
4970
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
9
1504
by: Verizon News Server | last post by:
Hi, I am a newbie with Javascript. I am trying to build a simple form that calculates the cost of gasoline for a trip. It simply divides the trip distance by the mpg and multiplies that by the current per gallon price. It works, fine except I want to round the number to two decimals ( 64.16, not 64.166666666) Any help is greatly...
42
2028
by: lorlarz | last post by:
Contrary to what one authority in the JavaScript field says: JavaScript does make errors when dealing with just with integers. This authority (Douglas Crockford.) says: "integer arithmetic in floating point is exact" Well, I can prove this is incorrect with this program: http://mynichecomputing.com/digitallearning/yourOwn.htm This a...
16
1915
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi All, I have a neat little script that calculates price based on quantity without refreshing the page.. the script is - <script type="text/javascript"> function OpenWin(url) { window.open(url,'win','scrollbars=1,status=0,resizable=0,width=200,height=265'); }
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.