Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP! Deadline tomorrow! JAVA CALC

    Code:
    	valoareTreceri = parseInt($('#treceri1').attr('value'));
    	if(!valoareTreceri) {
    		valoare1 = 0;
    	} else {
    		if(tip=='tip1'||tip=='tip3') {
    			valoare1 = f8*1.25*(0.3*(valoareTreceri-1)+1);
    		}	
    	}
    I have this java code that calculates "valoare1" as the multiplication of f8 (f8 is a value given earlier in the code) with 1.25 then with 0.3 * "valoareTreceri" wich is a value from 0 to 6 (default 0) taken from html form.
    ex: if valoareTreceri=4 then
    valoare1=15*1.25*(0.3*(4-1)+1) =
    =15 * 1.25 * (1.9)= 35.62
    if valoaretreceri=5 then
    valoare1=15*1.25*(0.3*(5-1)+1)=
    =15 *1.25* (2.2) = 41.25
    So what happens is that valoare1 gets + 30% when valoareTreceri rises.

    I need that "valoare1" for each "valoareTreceri" (from 1 to 6) to be a fix value. Not to rise procentual. And to define it manualy for each 1 to 6.
    For example something like this: (the numbers are fictive)
    if valoareTreceri=1
    valoare1=f8+5
    if valoareTreceri=2
    vlaoare1=f8+19
    if valoareTreceri=3
    valoare1=f8+20
    if valoareTreceri=4
    valoare1=f8+38
    etc until 6

    This valoareTreceri is selected by user in html form and depending to it the price of product changes but not procentual as it is now.

    If you want to look at the calculation form or the entire code by inspecting element you`ll find it here: www.armedia.ro/test
    If i didn`t make myself clear i can give further explications. It`s late and I`m tired.

    PLEASE HELP!!!! I should present this to my boss tomorrow afternoon.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Is this code supposed to be Java or is it supposed to be JavaScript? You are asking about Java but have posted in the JavaScript forum. These are two completely different languages but from what you have posted it is difficult to say which of the two you are trying to use (although the first line of the code does look like poorly written JavaScript).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I don't get it.

    Why did you give this example:
    Code:
    if valoareTreceri=4 then
    valoare1=15*1.25*(0.3*(4-1)+1) = 
    =15 * 1.25 * (1.9)= 35.62
    if valoaretreceri=5 then
    valoare1=15*1.25*(0.3*(5-1)+1)=
    =15 *1.25* (2.2) = 41.25
    Which of course could be done without any "if"s as simply:
    Code:
    valoare1=15*1.25*(0.3*(valoareTreceri-1)+1);
    And then change your mind and give these:
    Code:
    if valoareTreceri=4
    valoare1=f8+38
    ... etc. ...
    Which is it?
    Last edited by Old Pedant; 07-04-2013 at 12:36 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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