Jump to content

Search the Community

Showing results for tags 'rounding'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 2 results

  1. chob1234

    Rounding

    Confused on why my toFixed(2) function is not rounding my output. Located at the bottom of my code here. My output is "501327.3600770543" //// Get the sq inch. for BuildIDs that start with AA and //// sets value to the "result" variable var result=0; var params = { maxItems: 100000 /* NUMBER */ }; //// result: INFOTABLE var itPartInfo = Things["Training.InfoTable.PartInfo"].GetDataTableEntries(params); // Return square inches of Oak needed for each build ID that starts with AA // Like type filters by a like criteria // filters rows from Infotable PartInfo var query = { filters: { "type": "AND", filters: [ { "fieldName": "BuildID", "type": "LIKE", "value": "AA*" }, { "fieldName": "MaterialType", "type": "EQ", "value": "Oak" } ] } }; var oakparams = { t: itPartInfo /* INFOTABLE */, query: query /* QUERY */ }; // result: INFOTABLE var sqresult = Resources["InfoTableFunctions"].Query(oakparams); //Infotable for loop snippet var tableLength = sqresult.rows.length; // for loop will loop through itPartInfo, calculate the sq. in. for each part that starts with AA and return // sq. in. in "result" for (var x = 0; x < tableLength; x++) { var row = sqresult.rows[x]; //Your code here //+= addition assignment operator is basically same as "x = x + y" result += (row.Height*row.Width); result.toFixed(2); }
  2. I am working in xslt 1.0, and cannot use extensions & am limited as to what namespaces can be used (currently only http://www.w3.org/1999/XSL/Transform can be used). Another limitation I am working with is the 3rd party application I am using will not properly process includes or imports into the XSL. In other words - the xslt that I need to use must be pretty much self-inclusive, in that whatever is called or referenced must be in the xslt itself & nowhere else. I had decided to try to do a conversion to Julian date & mimic how Excel might do the conversion. I've got the date part figured out, but the hour part is what I'm having trouble with. The example I am using is:Start Time = 08:19:37End Time = 15:58:33 which is a duration/difference of 7:38:56 (BTW, this is only for same-day calculation - I have it to throw an error if Endtime < Start Time or if the Day is > 0). To arrive at the time, I convert everything to seconds & then do the math.08:19:37 converts to 29977 (8 * 3600 for hours + 19 * 60 for minutes + seconds).15:58:33 converts to 57513 (15 * 3600 for hours + 58 *60 for minutes + seconds). The difference is 27536 seconds. I get:27536/3600 =7.6488888888888888888 <-- the integer part is hoursthen the difference of 27536 - 25200 = 2336 <-- the 25200 = 7 hours * 3600 seconds2336/60 = 38.93333333333333333 <-- the integer part is 38 minutesthen the difference of 2336 - 2280 = 56 seconds from above. However, if I try to grab the integer portion of these numbers, its subject to rounding. <xsl:template name="time-difference"> <xsl:param name="from-hour"/> <xsl:param name="from-minute"/> <xsl:param name="from-second"/> <xsl:param name="to-hour"/> <xsl:param name="to-minute"/> <xsl:param name="to-second"/><xsl:variable name="f-secs" select="($from-hour * 3600) + ($from-minute * 60) + ($from-second)"/><xsl:variable name="t-secs" select="($to-hour * 3600) + ($to-minute * 60) + ($to-second)"/><xsl:variable name="sec-diff" select="$t-secs - $f-secs"/><xsl:variable name="daysec-diff" select="format-number(($sec-diff div 86400),'#')"/><xsl:variable name="q" select="($sec-diff div 3600)"/><xsl:variable name="t-hrs-diff" select="format-number(($sec-diff div 3600),'00')"/>.......</xsl:template> The variable q above has 7.648888888888888888 (which is correct)however, the t-hrs-diff once the format-number happens now has "08" in it, making my time incorrect. I know any other formatting attempt to grab the integer portion of the number would result in rounding. Outside of the substring-before & substring-after - which would (I think) make me have to convert the result to a number before using in the next calculation - is there ANY other way to grab the unaltered integer portion of the number & not have to do conversion from a string to number to use the pieces? Is there a better way to do this, given the limitations I have? I would appreciate any thoughts or suggestions. Thanks!
×
×
  • Create New...