Thanks:  0
Likes:  0
Dislikes:  0

1. ## 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. ## Re: Truncate decimals

this = 2.13

this = FormatNumber(this,1)

print this

3. ## Re: Truncate decimals

I believe that this function does rounding up.

4. ## 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. ## 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. ## Re: Truncate decimals

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

7. ## 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. ## 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. ## Re: Truncate decimals

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

10. ## Re: Truncate decimals

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

#### 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.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.