JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 10th, 2010, 03:04 PM
dashndash dashndash is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 1 dashndash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 7 sec
Reputation Power: 0
Talking Total upto 2 Decimal numbers...

hi I've been reading on this forum since 2 months.... Just now registered.... I'm stucked in a javascript, which shows total price when customer enters quantities instantly....


But the problem is, it gives some thing like 23.549999999999997 for quantity of 3.........


I want it to be 23.54..... Hope you got my point..... Please help me... I'm about to pull my hair now!!!!


Quote:


<html>

<script type="text/javascript">
function num(id) {
var e = document.getElementById(id);
if (e != null) {
var v = e.value;
if (/^\d+$/.test(v)) {
return parseInt(v, 10);
}t
}
return 0;
}

function sum() {


var v1 = num("v1");
var r = document.getElementById("result");
if (r != null) {
r.value = v1 * 7.85;

}
}

function addHandler(element, eventName, handler) {
if (element.addEventListener) {
element.addEventListener(eventName, handler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + eventName, handler);
}
}



addHandler(window, "load",
function() {
addHandler(document.getElementById("v1"), "keyup", sum);

});
</script>
<head><head/>

<body>

<!-- Start HTML form -->
<form name="form" method="post" id="third" action="ex2.php" class="niceform">
<h1>Fill Out Your Order Details</h1>
<!-- Name -->
<label for="name"><strong><strong class="blue">*</strong> <span class="bisg">Name :</span></strong></label>
<input id="name" name="name" type="text" class="validate['required','length[3,-1]','nodigit']" size="20" />

<!-- Email -->
<label for="email"><strong><strong class="blue">*</strong> <span class="bisg">Email : </span></strong></label>
<input id="email" name="email" type="text" class="validate['required','length[5,-1]','email']" size="20" />

<!-- Website -->
<label for="site" class="bisg"><strong>Website :</strong> </label>
<input id="url" name="url" type="text" class="validate['url']" size="20" />

\
<label for="subject"><strong><strong class="blue">*</strong> <span class="bisg">city :</span></strong> </label>
<input id="city" name="city" type="text" class="validate['required']" size="20" />




<label for="msg"><strong><strong class="blue">*</strong> <span class="bisg">comments :</span></strong></label><br />
<textarea id="details" name="details" type="text" class="validate['required']" rows="10" cols="30"></textarea>

<label for="subject"><strong><strong class="blue">*</strong> No. of Items : </strong></label>
<input id="v1" name="articles" type="text" class="validate['required']" size="20" />

<!-- Total -->
<label for="subject"><strong><strong class="blue">*</strong> <span class="bisg">Total : </span></strong></label>
<strong class="blue">$</strong><input name="total" type="text" id="result" size="10" readonly>

<!-- Spam Check -->
<label for="spamcheck"><strong class="blue">*</strong> <acronym class="bisg" title="[ Spam prevention ]"><strong>Are you human?</strong></acronym> : <span class="bisgc"><strong class="bisgc">2 + 3 = ???</strong></span></label>
<input id="spamcheck" name="spamcheck" type="text" size="5" class="validate['required','number','spamcheck']" />
<br /><br />
<input type="submit" class="buttonSubmit" value="Send it!" />




<!-- Niceforms: mouse over effect -->
<!-- Do not remove the line below -->
<div id="stylesheetTest"></div>

</form>



I want TOTAL to be upto 2 Decimal numbers... That's it!!

Please find a way out for me!!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Total upto 2 Decimal numbers...


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap