1. substr

scenario 1

tt=94999999.12344455;
pause(substr(tt,10,6));

According to my understanding, it should print 123444,

but it's printing only 12, is there any cause for it...

scenario 2

tt =1.12344455;
pause(substr(tqt,3,6));

but this is pinting 123444

can anyone able to explain the diff

2. Re: substr

It appears WinRunner is truncating your value in Scenario 1. If you run the following code, you'll see the result of the truncation:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">tt=94999999.12344455;
pause(tt);</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Consider treating the value as a string to avoid the numerical truncation. If you run this scenario, you'll receive the expected result:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">tt=&quot;94999999.12344455&quot;;
pause(substr(tt,10,6));</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

3. Re: substr

So How can i truncate the values in integers

For eg:

33333.8888897777

I just want to display it as 33333.888889

4. Re: substr

Easiest way I know of, if you do not mind the last digit rounding to the nearest value, is:

value = "33333.8888897777";
rounded = sprintf("%.6f", value);
pause(rounded);

If you truly want to truncate, you could do something like:

value = "33333.8888897777";
split(value, myArray, ".");
myArray[2] = substr(myArray[2], 1, 6);
truncated = sprintf("%s.%s", myArray[1], myArray[2]);

5. Re: substr

Thanks for the reply .But u have declare the value as String.value = "33333.8888897777";
But if i remove the Quotes and execute the same thing , i am not getting the value which i want.Here rounding to zero should not be excepted.
how i can get this with out the quotes??

6. Re: substr

You can in effect "cast" a number to a string using sprintf:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">value = 33333.8888897777;
split(sprintf(&quot;%.10f&quot;, value), myArray, &quot;.&quot;
myArray[2] = substr(myArray[2], 1, 6);
truncated = sprintf(&quot;%s.%s&quot;, myArray[1], myArray[2]);
pause(truncated);</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">(Change the number in the "%.10f" expression to however many decimal positions of precision you need.)

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.