Cost Calculation Function With Parsed Numbers to Currency: Need Help Combining Functions

Discussion in 'HTML' started by Neredbojias, Oct 3, 2005.

  1. Neredbojias

    Neredbojias Guest

    With neither quill nor qualm, Fred quothed:

    > I'm trying to validate this script so the number entered is parsed
    > and a dollar sign is automatically entered before the number onBlur.
    >
    > My problem is that when I do this, the script interoperates the dollar
    > sign as a character and not a numerical number and the script crashes
    > (NaN).


    It should be easy to strip the $ before processing, no??

    --
    Neredbojias
    Contrary to popular belief, it is believable.
     
    Neredbojias, Oct 3, 2005
    #1
    1. Advertising

  2. Neredbojias

    Fred Guest

    I'm trying to validate this script so the number entered is parsed
    and a dollar sign is automatically entered before the number onBlur.

    My problem is that when I do this, the script interoperates the dollar
    sign as a character and not a numerical number and the script crashes
    (NaN).

    FYI: When I tested it, I executed the funtion via a double onBlur
    call from the text box.

    My best guess to resolving the issue is to insert the function within
    the script. How would I go about doing this with out crashing
    function calc()}?


    // Here's the working calculation functions - - - - - -
    // Here's the working calculation functions - - - - - -
    // Here's the working calculation functions - - - - - -

    function startCalc(){
    interval = setInterval("calc()",1);
    }
    function calc(){
    one = document.autoSumForm.firstBox.value;
    two = document.autoSumForm.secondBox.value;
    three = document.autoSumForm.thirdBox.value;
    four = document.autoSumForm.fourthBox.value;
    five = document.autoSumForm.fithBox.value;
    six = document.autoSumForm.sixthBox.value;
    var totalCost = (one * 1) + (two * 1) + (three * 1) + (four * 1) +
    (five * 1) + (six * 1);
    document.autoSumForm.seventhBox.value = totalCost;
    var fee = document.autoSumForm.TotalServiceFee.value;
    if ( fee != "" ) {
    var monthlySavings = totalCost - parseFloat(fee);
    var yearlySavings = monthlySavings * 12;
    document.autoSumForm.TotalMonthlySavings.value =
    monthlySavings;
    document.autoSumForm.TotalYearlySavings.value = ("" +
    yearlySavings).replace(/(\.[0-9]{2}).*$/g, "$1");
    }

    }
    function stopCalc(){
    clearInterval(interval);
    }
    function fillUp(radioBtn) {
    document.autoSumForm.TotalServiceFee.value = radioBtn.value;
    calc();


    }





    // Here's the working parse number to currency functions - -
    // Here's the working parse number to currency functions - -
    // Here's the working parse number to currency functions - -

    var prefix="$"
    var wd

    function parseelement(thisone){
    if (thisone.value.charAt(0)=="$")
    return
    wd="w"
    var tempnum=thisone.value
    for (i=0;i<tempnum.length;i++){
    if (tempnum.charAt(i)=="."){
    wd="d"
    break
    }

    }
    if (wd=="w")
    thisone.value=prefix+tempnum+".00"
    else{

    if (tempnum.charAt(tempnum.length-2)=="."){
    thisone.value=prefix+tempnum+"0"
    }
    else{
    tempnum=Math.round(tempnum*100)/100
    thisone.value=prefix+tempnum
    }
    }
    }



    How do I merge these two???
     
    Fred, Oct 3, 2005
    #2
    1. Advertising

  3. Neredbojias

    Fred Guest


    >
    >It should be easy to strip the $ before processing, no??



    I was thinking after processig.

    How would you do it? Can you post an example?
     
    Fred, Oct 4, 2005
    #3
  4. Neredbojias

    Neredbojias Guest

    With neither quill nor qualm, Fred quothed:

    >
    > >
    > >It should be easy to strip the $ before processing, no??

    >
    >
    > I was thinking after processig.
    >
    > How would you do it? Can you post an example?


    Well, in javascript it'd be simply:

    var a;
    ....
    ....
    a=a.slice(1);

    (You could also use regexp replace.)

    If you have to verify whether or not the "$" is there:

    if (a.slice(0,1)=="$") {
    a=a.slice(1);
    }

    There's similar functions in php, etc.

    --
    Neredbojias
    Contrary to popular belief, it is believable.
     
    Neredbojias, Oct 4, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    423
    Gabriel Genellina
    May 14, 2007
  2. Replies:
    5
    Views:
    582
    Keith Thompson
    Jul 15, 2007
  3. Malcolm Greene
    Replies:
    0
    Views:
    292
    Malcolm Greene
    Apr 9, 2008
  4. Jeff Uchtman

    Numbers (currency) to words.

    Jeff Uchtman, Aug 2, 2004, in forum: ASP General
    Replies:
    3
    Views:
    553
    Bullschmidt
    Aug 4, 2004
  5. GIMME
    Replies:
    5
    Views:
    189
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page