SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Rounding to a specific decimal place

    I am using TestComplete 4.25 and C#Script. My script reads some values from textboxes and then performs calculations using those values. After the calculations are performed, I would like to round the results to 2 decimal places for use later in the script.

    For example,
    temp1 = 42.2200004
    I need to round this value to : 42.22

    The value can be truncated as the more precise decimal places are not used. Any help would be appreciated.

  2. #2
    Member
    Join Date
    Oct 2002
    Posts
    78
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Rounding to a specific decimal place

    Hi,

    C#Script is based on JScript, so you can use all of the methods of JScript in scripts written in C#Script. To round a number to a specific number of digits after the decimal point, you can use the toFixed method:
    <font class="small">Code:</font><hr /><pre>
    var num = 3.256, precision = 2;
    num = num.toFixed(precision);
    </pre><hr />
    However, please note that this method returns a string. If you are going to use this result in further calculations, you need to create a new number:
    <font class="small">Code:</font><hr /><pre>
    num = new Number(num);
    </pre><hr />
    Please refer to the MSDN Library for more information about the toFixed method:
    http://msdn.microsoft.com/library/defaul...bbfe2330aa9.asp
    Regards,
    Leo - AQA Support

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Rounding to a specific decimal place

    Thanks for the help. Worked perfectly.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:22 PM.

Copyright BetaSoft Inc.