Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Javascript result round up to 0 decimal places

Avatar of petewinter
petewinterFlag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScriptPHP
6 Comments1 Solution553 ViewsLast Modified:
See the code attached.

I want the result in the below text field rounded up to 0 decimal places.

Also what code do I need to use to print the result else way on the page?

Many Thanks
<script>
var allRates=new Array();
var obj;
        function onSelectChange(obj){
	var data=obj.options[obj.selectedIndex].value
	var sign1=document.getElementById('CurrencySign1');
	var sign2=document.getElementById('CurrencySign2');
	var val="";
	var rate=0;
	if(data=="1")
	{
		rate=allRates[0].Rate;
		val="£";
		
	}
	if(data=="2")
	{
		rate=allRates[1].Rate;
		val="€";
		
	}
	if(data=="3")
	{
		rate=allRates[2].Rate;
		val="$";
		
	}
	var CP=document.getElementById('current_price').value
	var total=rate*90;
	document.getElementById('colorific_price').value=total
	sign1.innerHTML=val;
	sign2.innerHTML=val;
	}
	</script>
<form id="Savings_Calculator_Form" name="Savings_Calculator_Form" method="post" action="">
<input type="hidden" name="ink" id="ink" />
See how much you can save!
<table width="194" cellspacing="0" cellpadding="2" style="margin-top:5px;">
    <tr>
      <td colspan="3">Currency:
        <label><select name="currency" id="currency" onchange="onSelectChange(this)" style="width: 131px;">
          <?php
$exchangeRates="";
$initRate=-1;
do {  
?>
          <option value="<?php echo $row_rs_exchange_rate['id']?>"><?php echo $row_rs_exchange_rate['currency']?></option>
          <?php
$exchangeRates=$exchangeRates.'obj=new Object(); obj.ID=\''.$row_rs_exchange_rate['id'].'\';obj.Rate=\''.$row_rs_exchange_rate['rate'].'\'; allRates[allRates.length]=obj;';
if($initRate==-1)
{
$initRate=$row_rs_exchange_rate['rate'];
$initRate=$initRate*90;
}
} while ($row_rs_exchange_rate = mysql_fetch_assoc($rs_exchange_rate));
  $rows = mysql_num_rows($rs_exchange_rate);
  if($rows > 0) {
      mysql_data_seek($rs_exchange_rate, 0);
	  $row_rs_exchange_rate = mysql_fetch_assoc($rs_exchange_rate);

  }
?>
        </select></label></td>
      </tr>
    <tr>
      <td>Current Ink Price: <span id="CurrencySign1">£</span></td>
      <td colspan="2"><label><input name="current_price" type="text" id="current_price" style="width:64px"/></label></td>
    </tr>
        <tr>
      <td width="129">Colorific Ink Price: <span id="CurrencySign2">£</span></td>
      <td width="44"><label><input name="colorific_price" type="text" id="colorific_price" style="width:44px" value="<?echo $initRate;?>"/></label></td>
      <td width="21"><a class="info" href="javascript:void(0)"><img src="images/Info_Icon.gif" width="16" height="16" border="0"/><span>Colorific Bio Ink - RRP £90.00<br />Contact reseller for best price</span></a></td>
    </tr>
    <tr>
      <td colspan="3">Quantity used per month:
        <label><input name="quantity" type="text" id="quantity" style="width:41px" /></label></td>
      </tr>
  </table>
<script>
<?echo $exchangeRates;?>
</script>

<input type="submit" name="calc_button" id="calc_button" value="Calculate Savings" />
  
</form>
ASKER CERTIFIED SOLUTION
Avatar of pradyahuja
pradyahujaFlag of Australia image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers