facebook

Round to 2 decimals – i.e. 23.45 instead of 23.4467: CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #329190 Reply

    Please–Can someone help?
    Attached is my APP.
    If you put numbers in the WKLY Sales screen and enter the number of weeks and the number of days in the week results in numbers with 8 or 9 digits after the decimal point. I only want 2 after the decimal point.

    Can you help me with the code?

    Someone provided this example but I don’t understand where to put it and where to call it.

    function round(z){
    z=z*100;
    z=Math.round(z);
    z=z/100;
    return(z);
    }

    Thank you for your help.

    Celeste

    Attachments:
    You must be logged in to view attached files.
    #329193 Reply

    Kale
    Member

    Hi,

    the function can be placed anywhere. It is a function like any other function in your code and works exactly like your functions you already have.

    It is called, when you want a result to be rounded 😉

    For example:

    var number1 = 15;
    var number2 = 3.5:
    var result = round(number1/number2);

    The function round() is called and gets the result of number1/number2. It returns the rounded result.

    In your code you would write:

    //compute daily average of months
    davg = round( avg / mth8);

    Kale

    #329207 Reply

    THANK YOU, thank you, thank you! It worked, but of course you knew it would 🙂 !

    The problem that I was having was thinking it would be an “on click” or “on change” call in the MobiOne design. Also, I was trying to substitute the z in the function for my variables (davg, avg).

    I have two questions:

    1 – How does js know to substitute the z with my variable (davg)? It seems that it would be looking for a variable named z or your would have to substitute your variable for the z.

    2 – Can you suggest books or online learning or something that would help me? I have “Sams Teach Yourself HTML, CSS and JavaScript” by Julie Meloni, access to jquery.com and w3schools. Other suggestions?

    I have to present this to my Director next week and it is more or less complete except I have to figure out how to calculate the time difference between two dates. BUT THAT CAN WAIT! For example, if a process starts on 8/14/2012 at 10:00 AM and ends on 8/15/2012 at 1:00 PM, how many days and hours is that? (14/24=.583 and 13/24=.542–.583+.542=1.12 days). BUT THAT CAN WAIT.

    I can’t express how appreciative I am of your help. I realize that Octavio and Wayne are busy and this is such a great resource to have.

    Thank you again.

    Celeste

    #329237 Reply

    Kale
    Member

    You’re welcome.

    How does js know to substitute the z with my variable (davg)? It seems that it would be looking for a variable named z or your would have to substitute your variable for the z.

    Well, it does not substitute the variables. What happens is that the result of the calculation (avg/mth8), let´s say it is 6.23334267365, is passed to the function round(z)

    The z is a local variable of that function and when you pass the result of the calculation, then z=6.23334267365

    Then the function rounds the number to 6.23

    It then returns the value back to where the function was called. NOW the variable davg gets the value of 6.23

    Can you suggest books or online learning or something that would help me? I have “Sams Teach Yourself HTML, CSS and JavaScript” by Julie Meloni, access to jquery.com and w3schools. Other suggestions?

    My books are all in german 😉 I don´t know any english books about javascript. Maybe someone else has a suggestion?

    Kale

    #329272 Reply

    Thanks again Kale. I will make this a separate topic.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Round to 2 decimals – i.e. 23.45 instead of 23.4467: CLOSED

You must be logged in to post in the forum log in