SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Member
    Join Date
    Jan 2009
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Truncate decimals

    Hi,
    treid to search, did not find anything like that here. Anyways, maybe someone knows.
    I have numbers with decimals like 2.13 and 2.12. Is there a way to truncate decimals in those numbers? like to be 2.1. I do not need rounding up. Thank you in advance

  2. #2
    Member
    Join Date
    Oct 2003
    Location
    Norfolk, VA
    Posts
    360
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    Use FormatNumber. Per your example:

    this = 2.13

    this = FormatNumber(this,1)

    print this
    A good rule of thumb is to never measure with your thumb.

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    I believe that this function does rounding up.

  4. #4
    Member
    Join Date
    Apr 2009
    Location
    San Diego
    Posts
    413
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    Sorry but your objective is not very clear. Can you please provide a decimal number from your AUT and what the string should look like after the decimals are removed.

    Cheers~

  5. #5
    Member
    Join Date
    Jan 2009
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    ok the thing is I have expected amount which is doing calculation and actual amount that is taken from screen.
    results can be like that
    Expected 2.68 Actual 2.67
    or
    2.13 2.12
    or
    1.07 1.06

    it fails as you may see, so I thought to get results with one decimals after dot like 2.6 or 2.13 or 1.0

  6. #6
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    Check this, it might help you.

    ExpectedVal = "2.13"
    ActualVal= "2.12"
    If ExpectedVal - ActualVal = 0 OR ExpectedVal - ActualVal <= 0.01Then
    Msgbox "Pass"
    Else
    Msgbox "Fail"
    End If

  7. #7
    Member
    Join Date
    Jan 2009
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    Thanks TReddy, but values can be different all the time depends on requirements of driver script. Therefore I cannot use as you offered unfortunately. that's why i asked if there is a way.

  8. #8
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    It doesn't mean you have to use hard coded values like in the example I have given above. You will need to understand the logic and use it in your code for any values with parametrization.

  9. #9
    Member
    Join Date
    Jan 2009
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    I see, but as far you know there is nothing as truncating decimals like just numbers?

  10. #10
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Truncate decimals

    Look at Mid, Len, Instr, Isnumeric and Round functions in the online help.

 

 
Page 1 of 2 12 LastLast

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 10.00%
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 04:27 PM.

Copyright BetaSoft Inc.