Back to top

Autore Topic: Modulo per le conversioni - problema con notazione scientifica  (Letto 2518 volte)

Offline eliospeppe

  • Appassionato
  • ***
  • Post: 255
  • Sesso: Maschio
  • Cyborg felice!
    • Mostra profilo
Salve, ragazzi
non so se è la sezione giusta.
ma avrei un problema con il codice php, peraltro anche un pò stupidino, ma mi sono bloccato.
la pagina in esame è questa:  http://ingfama.com/index.php/fattori-di-conversione
in pratica ho fatto in modo che tutti i numeri siano in formato scientifico, ma non riesco con il primo numero, quello che 'detta' le formule, dove sbaglio?
questo è il codice (siate liberi di copiarlo e usarlo come volete) ;D




Codice: [Seleziona]
<?php






// no direct access
defined('_JEXEC') or die('Restricted access');


?>

<SCRIPT LANGUAGE="JavaScript">




function mConvertVelocity(oform, mtype)
{
// velocità
var kmh = oform["km/h"];
var ms = oform["m/s"];


switch(mtype)
{
case 0:
  temp = ( kmh.value * 0.27777777777778);
  ms.value = temp.toExponential(5);
  break;
case 1:
  temp = ( ms.value * 3.60);
  kmh.value = temp.toExponential(5);
  break;
}
;


}


function mConvertForza(oform, mtype)
{
// forza
var N = oform["N"];
var kg = oform["kg"];


switch(mtype)
{
case 0:
  temp = ( N.value * 0.10189679820536350);
  kg.value = temp.toExponential(5);
  break;
case 1:
  temp = ( kg.value * 9.8070);
  N.value = temp.toExponential(5);
  break;       
default:
  break;
}
;


}




function mConvertPressione(oform, mtype)
{
// pressione
var Pa = oform["Pa"];
var bar = oform["bar"];
var kgmq = oform["kgmq"];
var ata = oform["ata"];
var atm = oform["atm"];
var mH2O = oform["mH2O"];


switch(mtype)
{
case 1:
  Pa.value = bar.value / 0.000010;
  break;
case 2:
  Pa.value = kgmq.value / 0.1019679820536350;
  break;       
case 5:
  Pa.value = mH2O.value / 0.0001020;
  break;       
case 6:
  Pa.value = ata.value / 0.00001019679820536350;
  break;       
case 7:
  Pa.value = atm.value / 0.0000098710;
  break;       
default:
  break;
}


temp = Pa.value * 0.000010;
bar.value = temp.toExponential(5);


temp = Pa.value * 0.1019679820536350;
kgmq.value = temp.toExponential(5);


temp = Pa.value * 0.0001020;
mH2O.value = temp.toExponential(5);


temp = Pa.value * 0.00001019679820536350;
ata.value = temp.toExponential(5);


temp = Pa.value * 0.0000098710;
atm.value = temp.toExponential(5);


temp = Pa.value;
Pa.value = Math.round(temp);


}






function mConvertPotenza(oform, mtype)
{
// potenza
var W  = oform["W"];
var kgms = oform["kgms"];
var kCalh = oform["kCalh"];
var kw = oform["kw"];
var cv = oform["cv"];
var hp = oform["hp"];
var btuh = oform["btuh"];


switch(mtype)
{
case 1:
  W.value = kgms.value / 0.1019679820536350;
  break;
case 2:
  W.value = kCalh.value / 0.860;
  break;       
case 5:
  W.value = kw.value / 0.010;
  break;       
case 6:
  W.value = cv.value / 0.001358695652173910;
  break;       
case 7:
  W.value = hp.value / 0.001340482573726540;
  break;   
case 8:
  W.value = btuh.value / 3.4130;
  break;   
default:
  break;
}


temp = W.value * 0.1019679820536350;
kgms.value = temp.toExponential(5);


temp = W.value * 0.860;
kCalh.value = temp.toExponential(5);


temp = W.value * 0.010;
kw.value = temp.toExponential(5);


temp = W.value * 0.001358695652173910;
cv.value = temp.toExponential(5);


temp = W.value * 0.001340482573726540;
hp.value = temp.toExponential(5);


temp = W.value * 3.4130;
btuh.value = temp.toExponential(5);


temp = W.value;
W.value = Math.round(temp);


}




function mConvertEnergia(oform, mtype)
{
// energia
var Joule  = oform["Joule"];
var kgm = oform["kgm"];
var wh = oform["wh"];
var kcal = oform["kcal"];
var kwh = oform["kwh"];
var btu = oform["btu"];
var tep = oform["tep"];


switch(mtype)
{
case 1:
  Joule.value = kgm.value / 0.1019679820536350;
  break;
case 2:
  Joule.value = wh.value / 0.000277777777777778;
  break;       
case 5:
  Joule.value = kcal.value / 0.0002388915432393690;
  break;       
case 6:
  Joule.value = kwh.value / 0.000000277777777777778;
  break;       
case 7:
  Joule.value = btu.value / 0.0009480;
  break;   
case 8:
  Joule.value = tep.value / 0.000000000023880;
  break;   
default:
  break;
}


temp = Joule.value * 0.1019679820536350;
kgm.value = temp.toExponential(5);


temp = Joule.value * 0.000277777777777778;
wh.value = temp.toExponential(5);


temp = Joule.value * 0.0002388915432393690;
kcal.value = temp.toExponential(5);


temp = Joule.value * 0.000000277777777777778;
kwh.value = temp.toExponential(5);


temp = Joule.value * 0.0009480;
btu.value = temp.toExponential(5);


temp = Joule.value * 0.000000000023880;
tep.value = temp.toExponential(5);


temp = Joule.value;
Joule.value = Math.round(temp);


}






</SCRIPT><form action="../cgi-bin/mycgi.pl" method=POST>
  <table width="100%" border="0">
    <tr>
      <td><p><font size="+1"><strong>VELOCITA'[br /]
                <input name="km/h" onchange="mConvertVelocity(this.form, 0)" />
        km/h[br /]
  <input name="m/s" onchange="mConvertVelocity(this.form, 1)" />
        m/s[br /]
      </strong></font></p>
        <p><font size="+1"><strong>FORZA [br /]
                <input name="N" onchange="mConvertForza(this.form, 0)" />
          N[br /]
  <input name="kg" onchange="mConvertForza(this.form, 1)" />
      kg</strong></font></p>


<p><font size="+1"><strong>ENERGIA [br /]
          <input name="Joule" onchange="mConvertEnergia(this.form, 0)" />
          Joule[br /]
          <input name="kgm" onchange="mConvertEnergia(this.form, 1)" />
          kgm[br /]
          <input name="wh" onchange="mConvertEnergia(this.form, 2)" />
          Wh/h[br /]
          <input name="kcal" onchange="mConvertEnergia(this.form, 5)" />
          kCal[br /]
          <input name="kwh" onchange="mConvertEnergia(this.form, 6)" />
          kWh[br /]
          <input name="btu" onchange="mConvertEnergia(this.form, 7)" />
      Btu[br /]
          <input name="tep" onchange="mConvertEnergia(this.form," />
      TEP[br /]
</strong></font></p>




</td>
      <td><p>&nbsp;</p>
        <p><font size="+1"><strong>PRESSIONE [br /]
          <input name="Pa" onchange="mConvertPressione(this.form, 0)" />
          Pa[br /]
          <input name="bar" onchange="mConvertPressione(this.form, 1)" />
          bar[br /]
          <input name="kgmq" onchange="mConvertPressione(this.form, 2)" />
          kg/mq[br /]
          <input name="mH2O" onchange="mConvertPressione(this.form, 5)" />
          mH2O[br /]
          <input name="ata" onchange="mConvertPressione(this.form, 6)" />
          ata[br /]
          <input name="atm" onchange="mConvertPressione(this.form, 7)" />
      atm </strong></font></p>




<p><font size="+1"><strong>POTENZA [br /]
          <input name="W" onchange="mConvertPotenza(this.form, 0)" />
          W[br /]
          <input name="kgms" onchange="mConvertPotenza(this.form, 1)" />
          kgm/s[br /]
          <input name="kCalh" onchange="mConvertPotenza(this.form, 2)" />
          kCal/h[br /]
          <input name="kw" onchange="mConvertPotenza(this.form, 5)" />
          kW[br /]
          <input name="cv" onchange="mConvertPotenza(this.form, 6)" />
          CV[br /]
          <input name="hp" onchange="mConvertPotenza(this.form, 7)" />
      HP[br /]
          <input name="btuh" onchange="mConvertPotenza(this.form," />
      Btu/h[br /]
</strong></font></p>












</td>
    </tr>
  </table>
  <p><font size="+1"><strong>[br /]
  </strong></font></p>
  <p>&nbsp;</p>
</form>
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST><BR>
</FORM>
 


 
</td>
</tr>
 
<tr>


 
</td>
</tr>
</table>












 
<SCRIPT LANGUAGE="JavaScript">


if (document.property_form.the_menu.selecte dIndex == 0){
   if (document.images){
      // Also, define the window name for correct targeting
      window.name="converter_main";
      FillMenuWithArray(document.form_A.unit_menu, unit[0]);
      FillMenuWithArray(document.form_B.unit_menu, unit[0]);
   } else {


      alert("The browser you are using doesn't Support Javascript. Install java to use the converter..");
   }
}


</SCRIPT>

tenchiù!!!! ;)
« Ultima modifica: 22 Mag 2012, 17:24:42 da eliospeppe »
La risposta è dentro di te...che però è sbagliata!
Il mio sito

Offline webbati

  • Esploratore
  • **
  • Post: 116
    • Mostra profilo
Re:Modulo per le conversioni - problema con notazione scientifica
« Risposta #1 il: 22 Mag 2012, 18:28:00 »
perchè nei case ad esempio della pressione dove fai lo switch di mtype ti aspetti un intero da 1 a 7 ( saltando 3 e 4 )  ma nel form parti da 0
« Ultima modifica: 22 Mag 2012, 18:32:35 da webbati »

Offline eliospeppe

  • Appassionato
  • ***
  • Post: 255
  • Sesso: Maschio
  • Cyborg felice!
    • Mostra profilo
Re:Modulo per le conversioni - problema con notazione scientifica
« Risposta #2 il: 22 Mag 2012, 18:46:20 »
grazie tante, funziona ;)
La risposta è dentro di te...che però è sbagliata!
Il mio sito

 



Web Design Bolzano Kreatif