Results 1 to 2 of 2
  1. #1
    Joskhuu is offline Member
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Question Help needed with custom code

    Hello to ya'll

    I'm a beginner with java and i'm trying to make a calculatorisch code.
    The thing is that everything seems to be working fine, but soms calculations are displayed wrong. Is't a bit off a long code but i'm still a noob ;-)

    This is my code:

    Java Code:
    function update(form)
    	{
    	var grijzestroom = form.grijzestroom.value;
    	var stadsverwarming = form.stadsverwarming.value;
    	var grijsgas = form.grijsgas.value;
    	var dieselauto = form.dieselauto.value;
    	var benzineauto = form.benzineauto.value;
    	var lpgauto = form.lpgauto.value;
    	var trein = form.trein.value;
    	var bustram = form.bustram.value;
    	var goederendiesel = form.goederendiesel.value;
    	var goederenbezine = form.goederenbezine.value;
    	var drinkwater = form.drinkwater.value;
    	var kortevliegreis = form.kortevliegreis.value;
    	var langevliegreis = form.langevliegreis.value;
    
    	var grijzestroomco2 = grijzestroom*0.455;
    	form.grijzestroomco2.value = (grijzestroomco2).toFixed(2);
    	
    	var stadsverwarmingco2 = stadsverwarming*0.020;
    	form.stadsverwarmingco2.value = (stadsverwarmingco2).toFixed(2);
    	
    	var grijsgasco2 = grijsgas*1.770;
    	form.grijsgasco2.value = (grijsgasco2).toFixed(2);
    	
    	var dieselautoco2 = dieselauto*0.205;
    	form.dieselautoco2.value = (dieselautoco2).toFixed(2);
    	
    	var benzineautoco2 = benzineauto*0.215;
    	form.benzineautoco2.value = (benzineautoco2).toFixed(2);
    	
    	var lpgautoco2 = lpgauto*0.175;
    	form.lpgautoco2.value = (lpgautoco2).toFixed(2);
    	
    	var treinco2 = trein*0.031;
    	form.treinco2.value = (treinco2).toFixed(2);
    	
    	var bustramco2 = bustram*0.100;
    	form.bustramco2.value = (bustramco2).toFixed(2);
    	
    	var goederendieselco2 = goederendiesel*3.135;
    	form.goederendieselco2.value = (goederendieselco2).toFixed(2);
    
    	var goederenbezineco2 = goederenbezine*2.780;
    	form.goederenbezineco2.value = (goederenbezineco2).toFixed(2);
    	
    	var drinkwaterco2 = drinkwater*0.300;
    	form.drinkwaterco2.value = (drinkwaterco2).toFixed(2);
    
    	var kortevliegreisco2 = kortevliegreis*0.270;
    	form.kortevliegreisco2.value = (kortevliegreisco2).toFixed(2);
    	
    	var langevliegreisco2 = langevliegreis*0.135;
    	form.langevliegreisco2.value = (langevliegreisco2).toFixed(2);
    	
    	var co2totaal = form.co2totaal.value;
    	form.co2totaal.value = (grijzestroomco2+stadsverwarmingco2+grijsgasco2+dieselautoco2+benzineautoco2+lpgautoco2+treinco2+bustramco2+goederendieselco2+goederenbezineco2+drinkwaterco2+kortevliegreisco2+langevliegreisco2).toFixed(2);
    
    	var grijzestroomrel = form.grijzestroomrel.value;
    	var grijzestroomrel2 = (grijzestroomco2/co2totaal);
    	form.grijzestroomrel.value = (grijzestroomrel2 * 100).toFixed(2);
    
    	var stadsverwarmingrel = form.stadsverwarmingrel.value;
    	var stadsverwarmingrel2 = (stadsverwarmingco2/co2totaal);
    	form.stadsverwarmingrel.value = (stadsverwarmingrel2 * 100).toFixed(2);
    	
    	var grijsgasrel = form.grijsgasrel.value;
    	var grijsgasrel2 = (grijsgasco2/co2totaal);
    	form.grijsgasrel.value = (grijsgasrel2 * 100);
    	
    	var dieselautorel = form.dieselautorel.value;
    	var dieselautorel2 = (dieselautoco2/co2totaal);
    	form.dieselautorel.value = (dieselautorel2 * 100).toFixed(2);
    	
    	var benzineautorel = form.benzineautorel.value;
    	var benzineautorel2 = (benzineautoco2/co2totaal);
    	form.benzineautorel.value = (benzineautorel2 * 100).toFixed(2);
    	
    	var lpgautorel = form.lpgautorel.value;
    	var lpgautorel2 = (lpgautoco2/co2totaal);
    	form.lpgautorel.value = (lpgautorel2 * 100).toFixed(2);
    	
    	var treinrel = form.treinrel.value;
    	var treinrel2 = (treinco2/co2totaal);
    	form.treinrel.value = (treinrel2 * 100).toFixed(2);
    	
    	var bustramrel = form.bustramrel.value;
    	var bustramrel2 = (bustramco2/co2totaal);
    	form.bustramrel.value = (bustramrel2 * 100).toFixed(2);
    	
    	var goederendieselrel = form.goederendieselrel.value;
    	var goederendieselrel2 = (goederendieselco2/co2totaal);
    	form.goederendieselrel.value = (goederendieselrel2 * 100).toFixed(2);
    	
    	var goederenbezinerel = form.goederenbezinerel.value;
    	var goederenbezinerel2 = (goederenbezineco2/co2totaal);
    	form.goederenbezinerel.value = (goederenbezinerel2 * 100).toFixed(2);
    	
    	var drinkwaterrel = form.drinkwaterrel.value;
    	var drinkwaterrel2 = (drinkwaterco2/co2totaal);
    	form.drinkwaterrel.value = (drinkwaterrel2 * 100).toFixed(2);
    	
    	var kortevliegreisrel = form.kortevliegreisrel.value;
    	var kortevliegreisrel2 = (kortevliegreisco2/co2totaal);
    	form.kortevliegreisrel.value = (kortevliegreisrel2 * 100).toFixed(2);
    	
    	var langevliegreisrel = form.langevliegreisrel.value;
    	var langevliegreisrel2 = (langevliegreisco2/co2totaal);
    	form.langevliegreisrel.value = (langevliegreisrel2 * 100).toFixed(2);
    	
    	var reltotaal = form.reltotaal.value;
    	form.reltotaal.value = (grijzestroomrel+stadsverwarmingrel+grijsgasrel+dieselautorel+benzineautorel+lpgautorel+treinrel+bustramrel+goederendieselrel+goederenbezinerel+drinkwaterrel+kortevliegreisrel+langevliegreisrel);
    	
    }
    Working version can be seen here

    The thing is, when inserting the following numbers: 10,12,50,60,4,3,10,3,0,0,10,1,1 (verticly) the outcome of box 3 in the right colum should be 79,74 but it displays 79.83

    How is this possible ? i'm a noob so plz in plain englisch

    Kind reagards,
    Jos

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help needed with custom code

    I'm closing this thread as it is a Javascript question and has nothing to do with the focus of these forums, namely Java. I suggest that you Google for a Javascript forum and ask your question there. Best of luck.

Similar Threads

  1. Custom code validation
    By shivam0101 in forum Advanced Java
    Replies: 1
    Last Post: 01-13-2012, 02:40 PM
  2. Replies: 0
    Last Post: 03-17-2011, 01:07 PM
  3. needed a code for this
    By rajivjoshi in forum New To Java
    Replies: 2
    Last Post: 08-01-2010, 01:26 PM
  4. needed code for this output
    By rajivjoshi in forum New To Java
    Replies: 4
    Last Post: 05-31-2010, 06:54 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •