Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-20-2012, 05:18 PM   PM User | #1
mattsearle
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mattsearle is an unknown quantity at this point
problem with Math.round

Hi

I have tried various methods to introduce a Mathround function into the code below without success.

I am looking for the result to return an answer to 2 decimal places.

Any thoughts.


<link rel="stylesheet" type="text/css">

<style>

div
{
text-align: right;
padding: 1px;
margin: 1px;
color: #006666;
font-family: arial;
font-size:28pt;
font-weight:700;
background-color:
}

h1
{
text-align: right;
padding: 1px;
margin: 1px;
color: #006666;
font-family: arial;
font-size:9pt;
font-weight:
background-color:
}

</style>

<script type="text/javascript">

function calculate(inputId, outputId)

{

A = document.getElementById(inputId).value

outDiv = document.getElementById(outputId);

B =(parseInt(A) * 1);

//alert(A);

D = (parseInt(B) * 1);


if ( B <= 19)

{

tax1 = '**.**';

}

else if (B <= 30)

{

tax1 = (B * 3.95) * 1;

}

else if (B <= 40)

{

tax1 = (B * 3.75) * 1;

}

else if (B <= 50)

{

tax1 = (B * 3.70) * 1;

}

else if (B <= 60)

{

tax1 = (B * 3.55) * 1;

}

else if (B <= 70)

{

tax1 = (B * 3.40) * 1;

}

else if (B <= 80)

{

tax1 = (B * 3.25) * 1;

}

else if (B <= 90)

{

tax1 = (B * 3.10) * 1;

}

else if (B <= 100)

{

tax1 = (B * 2.95) * 1;

}

else if (B <= 150)

{

tax1 = (B * 2.80) * 1;

}

else if (B <= 200)

{

tax1 = (B * 2.65) * 1;

}

else

{

tax1 = (B * 2.60) * 1;

}

outDiv.innerHTML= '£'+tax1;


}

</script>

</HEAD>

<BODY>
<p style="margin-left: 3">
<h1 style="text-align: left">Enter Quantity (sq m)&nbsp;
<!--webbot bot="Validation" s-data-type="Number" s-number-separators=",." b-value-required="TRUE" i-minimum-length="2" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="20" s-validation-constraint="Less than or equal to" s-validation-value="999" --><INPUT id='inputA' NAME="text1" size="1" value="20" maxlength="3" />

<INPUT TYPE="button" VALUE="price" onClick="calculate('inputA', 'outputA')" style="color: #006666; font-family: Arial; font-size: 10px; position:relative; width:100; height:25"/></h1>
</p>

<div id='outputA' style="width: 0; height: -1"> </div>

<p style="margin-left: 3">
<h1 style="text-align: left">Enter Quantity (sq m)&nbsp;
<!--webbot bot="Validation" s-data-type="Number" s-number-separators=",." b-value-required="TRUE" i-minimum-length="2" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="20" s-validation-constraint="Less than or equal to" s-validation-value="999" --><INPUT id='inputB' NAME="text1" size="1" value="20" maxlength="3" />
<INPUT TYPE="button" VALUE="price" onClick="calculate('inputB', 'outputB')" style="color: #006666; font-family: Arial; font-size: 10px; position:relative; width:100; height:25"/></h1>
</p>
<div id='outputB' style="width: 0; height: -1"> </div>

<p style="margin-left: 3">
<h1 style="text-align: left">Enter Quantity (sq m)&nbsp;
<!--webbot bot="Validation" s-data-type="Number" s-number-separators=",." b-value-required="TRUE" i-minimum-length="2" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="20" s-validation-constraint="Less than or equal to" s-validation-value="999" --><INPUT id='inputC' NAME="text1" size="1" value="20" maxlength="3" />
<INPUT TYPE="button" VALUE="price" onClick="calculate('inputC', 'outputC')" style="color: #006666; font-family: Arial; font-size: 10px; position:relative; width:100; height:25"/></h1>
</p>
<div id='outputC' style="width: 0; height: -1"> </div>


</BODY>
</HTML></code></p>

</body>

</font>

</html>
mattsearle is offline   Reply With Quote
Old 12-20-2012, 05:29 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
you don't want Math.round, you want toFixed()

Code:
outDiv.innerHTML= '£'+tax1.toFixed(2);
the rest of your code is a mess, but that should solve the "two two places" problem
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:02 PM.


Advertisement
Log in to turn off these ads.