Results 1 to 4 of 4

Thread: Putting a limit on fractional digits displayed

  1. #1
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default Putting a limit on fractional digits displayed

    Is there a way to limit the number of digits to a decimal fraction in IE where in other browsers maxlength="10" does the job? IE usually creates a long unsightly string where perhaps only six or seven would be needed? For example, the difference between two times of birth calculated as a portion of a day does not need a long string of numbers (0.38541666666666663). How can I put a limit on IE's quotient to get something like 0.3854167?

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

  3. #3
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default

    'maxlength' already works fine in Mozilla. I added the two lines below, but it made no impact in Internet Explorer where the problem seems to be. Did I code it incorrectly?

    <script type="text/javascript">
    <!--

    // Define Portion of Day Between Birth Times -->

    function timeDifference(df){

    var ETBhr = df.ETBhr.selectedIndex + 1;
    var ETBmin = df.ETBmin.selectedIndex + 1;
    var LBThr = df.LBThr.selectedIndex + 1;
    var LBTmin = df.LBTmin.selectedIndex + 1;
    var answer = df.answer.value;
    var difference = [eval(df.ETBhr.selectedIndex)/24 +

    eval(df.ETBmin.selectedIndex)/1440] - [eval(df.LBThr.selectedIndex)/24 +

    eval(df.LBTmin.selectedIndex)/1440];
    df.answer.value = difference;
    var n = df.answer.value;
    n.toFixed(7);

    }

    // -->
    </script>

  4. #4
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    18
    Thanked 1 Time in 1 Post

    Default

    I have found two solutions to my little dilemma:
    1) df.answer.value = difference.toFixed(6);
    2) df.answer.value = difference.toPrecision(7);
    Problem solved. Thanks!

Bookmarks

Posting Permissions

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