Round Off This Calc To 2 Decimals?
Jan 3, 2010
First time user of Javascript and built an online calculator, trouble is I dont know where or how to code it so the answer ends with only 2 decimals
I have embedded code, Personally I think it's a miracle the darn thing works.:thumbsup: Link to page it's on [URL]...I have searched and read but after hours of trying stuff gave up.
<!--
function treevalue() {
document.volume.result.value=(((3.14159*((document.volume.radius.value)*(document.volume.radius.valu e)))*(document.volume.height.value))/3)*(document.volume.base.value)*(document.volume.e.value)*(document.volume.fv.value)*(document.volum e.l.value);
[Code]...
View 9 Replies
ADVERTISEMENT
Apr 27, 2009
I can'nt ffigure out how to round up the result of division 10/3 for example and to show only 3.33 as result
View 2 Replies
View Related
Sep 5, 2005
I have a javascript calculator that when you update a users level you click calculate and it updates there skill needed to reach the next level my problem is it only calculates as high as the number 2:
echo "<script langauage="javascript">
function calc() {
a = document.battle.newlevel.value;
b = 150;
c = document.battle.newskillneed.value;
answer = eval(a*a*b);
if(c>answer) {
document.battle.newskillneed.value = answer;
}
max.innerHTML = answer;
}
</script>";
Example: Level 2*(150 * Level 2) = 600 works fine but
Level 3*(150 * Level 3) = nothing why won't it work any higher its like there is a cap on how high it will go...
Also if I enter level 1 it comes up with 150 but if i put in level2 and press calculate it won't do anything but if i start out at level2 it works and then i move down to level 1 it works why won't it work moving up in numbers??
View 1 Replies
View Related
Apr 21, 2010
I am trying to use select options to get birthdate and calculate the age. I got the birthday with "birthDay = document.form1.selDate;" However i'm lost on the birthMonth and birthYear. I've looked at lots of examples. The birthMonth probably needs to be converted to integer, or use 1 thru 12 rather than Jan thru Dec. But birthYear i'd think would come back as a valid number. Is anyone familiar with this?
[Code]...
View 3 Replies
View Related
Nov 16, 2010
Don Gosselin's JavaScript Fourth Edition is a tiresome read and I have been unable to put together the necessary tools that Don teaches to find the answers that I want to make the following function work.
function calculate()
var shipping = 0;
var total = 0; {
if (document.forms[0].hand_tool.value != document.forms[0].hand_tool.value == true)
(document.forms[0]item1.value == 20); {
[Code]...
View 3 Replies
View Related
Apr 14, 2005
I have an alteration to do on a multi-page form which was previous in use for single item selection and calculations only.
Now the form has to be altered to process multiple items. My difficulties lie in tackling the javascript calulations for a form that populates dynamically with as many items as the user has previously selects.
Item recordID's are POSTed to this form as an array. The array determines which item records are pulled from the database via sql. The form has, for each record, a textfield for item quantity and subtotal, and a hidden input that holds the item cost price.
Previously, this was calculated by targeting hard coded form field names, however the dynamic nature of this form requires dynamic targeting or a different field naming strategy all together so that the javascript function can iterate through the form fields and calculate subtotals and total on the fly.
Here's the code so far;
The previous calculation function for the single item form:-
function calcForm(){
qty = parseFloat(document.confirmTicketPurchase.ticketQty.value)
if (isNaN(qty)){
alert("You must enter a valid number into the Enter Quantity field")
return false
}
if(qty <=0 || qty % 1 != 0 ){
alert("You must enter a quantity of tickets between 1 and 999 only")
return false
}
costPer = parseFloat(document.confirmTicketPurchase.perticketCost.value)
total = costPer*qty
document.confirmTicketPurchase.ticketCost.value = total
return true
}
I have to edit this javascript function to work with the following form and edit the form field names to suit the function.
The new form :-
<form action="#" name="confirmTicketPurchase" id="confirmTicketPurchase" method="POST">
<table border="0" cellpadding="2" cellspacing="1" class="dataTable">
<tr class="trTopRow">
<td colspan="2">You Have Selected The Following Ticket/s</td>
</tr>
<?php do { ?>
<tr class="trOdd">
<td colspan="2"><strong><?php echo $row_rsTickPurchase['ticketName']; ?></strong></td>
</tr>
<tr class="trEven">
<td width="36%">Enter Quantity:</td>
<td width="64%" class="algn_R"><input name="ticketQty" type="text" id="ticketQty" value="1" size="4" maxlength="4" onkeyup="calcForm()" /></td>
</tr>
<tr class="trEven">
<td>SubTotal:</td>
<td class="algn_R">
<input name="perticketCost" type="hidden" id="perticketCost" value="<?php echo $row_rsTickPurchase['ticketCost1']; ?>" />
<input name="ticketName" type="hidden" id="ticketName" value="<?php echo $row_rsTickPurchase['ticketName']; ?>" />
<input name="ticketID" type="hidden" id="ticketID" value="<?php echo $row_rsTickPurchase['ticketID']; ?>" />
$ <input name="ticketCost" type="text" id="ticketCost" size="12" readonly="true" /></td>
</tr>
<?php } while ($row_rsTickPurchase = mysql_fetch_assoc($rsTickPurchase)); ?>
<tr class="trOdd">
<td>TOTAL:</td>
<td class="algn_R">$
<input name="total" type="text" id="total" size="12" /></td>
</tr>
<tr>
<td colspan="2">Confirm your selection and proceed to Step 6</td>
</tr>
<tr class="trbtn">
<td colspan="2"><input name="userEmail" type="hidden" id="userEmail" value="<?php echo $_SESSION['email']; ?>" />
<input name="step" type="hidden" id="step" value="6" />
<input name="Submit" type="submit" class="loginBtn" value="Confirm" /></td></tr>
</table>
</form>
The calc function is called onLoad and during user input with onkeyup. I'd really appreciate some tips as to how to tackle this one. Currently I'm working on how to get the field names for each form field unique via the php loop which populates the form.
View 2 Replies
View Related
Jul 18, 2009
I know this is a rather odd post but I need to be able to convert a decimal to a fraction.Really all i need to know to get what i have to work is being able to tell if a number is whole or not. For instance if i have an accuracy set of .0625 = 1/16"If i take my variable which is set to .5625 (9/16")so if i take variable/accuracy in this case would equal 9. So this way i would know that the numerator would be 9 and my denominator would be 16.If i take the same accuracy of 1/16 and now introduce a variable of 0.5 then it will give me a remainder.
View 5 Replies
View Related
Sep 7, 2010
I have a problem that has my brain turning to goo...I have a function that mixed with php adds the total numerical valus from different dropdowns.
<?php if($z == 1) {?>
<script type="text/javascript"><!--
function updatesum() {
[code]....
View 23 Replies
View Related
Jul 26, 2005
this function is supposed to search a string for decimals and tell me how many of them it has found, but for some reason, it's not doing it right. since the "period" character is a special character in regular expressions,I went ahead and escaped it, but it's still doesn't work.
function ImprovedFormatAmount(ElementId)
{
var oElement = document.getElementById(ElementId);
var ElementValue = oElement.value;
var DecimalRegXp = /./g;
var OutputValue = ElementValue;
if (OutputValue.length > 0)
{alert (OutputValue.search(DecimalRegXp));}
}
View 9 Replies
View Related
Oct 12, 2011
I am trying to execute an .exe file on client side using javascript, say i want to run an pbrush or calc on client side click using JAVASCRIPT..
I tried this by embedding the following in source page of my web application(ASP.NET)
But i am getting an script error called Automation Server can't create an object
View 3 Replies
View Related
Apr 11, 2011
I have a script that allows ONLY numbers to be typed into a text field. I have tried to modify this script to allow Decimals (periods) to be typed as well, but haven't succeeded. The code in Red are the changes I added to this script, but it isn't working out.
function numbersOnly(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 110 || charCode > 110))
return false;
return true;
}
Second Problem: I need to set a Minimum number users may type in the text field. Normally this would be a simple task, but the minimum number they may type is a decimal (0.10). The default value in the field is .50. I tried replacing the .50 with .09, and I can't get the field to run the script and set its new value to .10 (<- this is the minimum). Here is the code I am working with.
[Code]...
View 5 Replies
View Related
May 24, 2011
How would I go about creating a random number between 1-50 that COULD include whole numbers, decimals to the tenth, hundredth and the thousandth place?
Ex) 2.145, 3, 5.8, 41.002, 10.12, 7, 18.023, 33.2
Also, if the only way to do it is to put trailing zeros to the thousandth place that's fine as well
Ex) 2.145, 3.00, 5.800, 41.002, 10.120, 7.00, 18.023, 33.200
View 7 Replies
View Related
Jul 10, 2009
I was wondering if anyone could help me with an 'adding commas to decimals' problem. I have figured out that I need an 'addCommas' function but I can't seem to figure out where and how to call it!This is my code:
function ClearForm(form){
form.days.value = "";
form.nrstaff.value = "";
[code]....
View 2 Replies
View Related
Mar 3, 2006
What it does is adds up quantities and gives you a total. Works fine with whole numbers but when you need to have cents - decimal point plus two, the email received does not show the quantities. Code:
View 1 Replies
View Related
Oct 12, 2009
I have a mortgage calc that is adding an extra decimal place to my interest rate. To see this in action go to: [URL]
Change the interest rate to 7.5
Click Calculate Payment
Click Create Amortization Chart
On the following screen you'll see a recap of your data and the interest rate will now say 7.55. Same thing happens if you enter 6.2. Next screen shows 6.22/. I've attached the html and js files in a zip.
View 2 Replies
View Related
Dec 13, 2010
I have some fields on my form that are auto-populating with a difference from 2 input fields using onChange, easy stuff. The correct value is stored in the DB, to 3 decimal places (correct, since data type is a float with 3 decimals).The challenge I am having is to get the number that is auto-displaying on the form to format to 3 decimals. For example, when I enter the first number at 44.8, and a second number of 44.666, the onChange command displays '0.13400000000000034'. This is saved in the db correctly as, '0.134' and once the form is submitted the correct value of 0.134 displays since it is pulling directly from the db. I would like to format the onChange display with the toFixed command so the extra decimals don't show onChange.
View 1 Replies
View Related
Aug 13, 2010
I need to round down to the nearest quarter hour (or .25 in decimal) via Javascript and have not come across any appropriate code yet.
View 4 Replies
View Related
Jul 23, 2005
I haven't found in my CSS book how to create a gradient to fill a division
tag, and to create a border with round corners.
Is it possible using either CSS or JavaScript? I'd like to create a menu bar with a gradient in the background, and I want the top corners to be a little round with a 5px radius.
View 3 Replies
View Related
Nov 8, 2011
Just started to learn java & came up with the following, but can't get the math.round to work. Anyone able to tell me where I'm going wrong please ? code...
View 9 Replies
View Related
Jul 22, 2002
To round off a value to a specified number of digits:
function RoundIt(Value,Digits) {
var P=Math.pow(10,Digits);
var R=Math.round(Value*P)/P;
var G=true;
while(G) {
R=String(R);
var L=R.length;
var I=R.indexOf('.');
if (I == -1) {
R=R+'.'
} else {
var D=L-I-1;
if (D < Digits) {
R=R+Ɔ'
} else {
G=false;
}
}
}
return R;
}
View 2 Replies
View Related
Jun 22, 2011
When rounding these 2 numbers in PHP and JS i get the following results:
22.044960000000003
PHP = 22.04
JS = 22.05 [code].....
}
I have tried many functions but cant seem to produce the same result as the PHP round. Does anyone have a solution to how can i get the same result using JS?
View 14 Replies
View Related
Nov 17, 2011
I am trying to use the following javascript [URL] to create something similar to the example on [URL] for a school project but I wondered if someone could advise me how I can round numbers to 2 decimal places in the field box as I have to convert the calculated value by an exchange rate, e.g.:
where x=100 and y=50
calculate="(x+y)/1.55"
returns a value of 96.77419355. I would like to round this figure up to 2 decimal places so it would read 96.77 but I cannot figure out how to do this.
View 6 Replies
View Related
Apr 30, 2009
Ive written this source
[Code]...
View 7 Replies
View Related
Nov 18, 2009
I use the following to round off to two decimal point.It works fine
function roundNumber(rnum, rlength) {
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
return newnumber;
}
[Code]....
how to get two decimal place instead of 1?
View 3 Replies
View Related
Dec 6, 2010
I have this js function:
<script type="text/javascript">
function updatesum() {
document.PaymentForm.newbalance.value = (document.PaymentForm.balance.value -0) - (document.PaymentForm.paymentamount.value -0);
}
</script>
I want to round the value of document.PaymentForm.newbalance.value to two decimal points.
View 8 Replies
View Related
Dec 3, 2010
i am using this jquery module to get rounded corners.http:[url]....This is my code. but i am not getting any rounded corners though i have correctly included the 2 .js files and have specified the correct div id name.
Code:
<script language="javascript" src="jquery.corner.js"></script>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">[code]....
View 6 Replies
View Related