Micro Focus QTP (UFT) Forums
Force calculated numbers to have 2 decimal places - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Force calculated numbers to have 2 decimal places (/Thread-Force-calculated-numbers-to-have-2-decimal-places)



Force calculated numbers to have 2 decimal places - Brian.Osborne - 06-29-2011

I need to be able to use a captured and calculated number as a basis of comparison for a checkpoint. The problem is when a number ends with a 0, it's left off of the calculated number.
This causes the checkpoint to fail.... 11.80 isn't the same 11.8

How can I force the calculated number to keep 2 placed to the right of the decimal, even if it's rounded to end with a 0?


RE: Force calculated numbers to have 2 decimal places - Vivek Mishra - 06-30-2011

You can use the Abs() function of VBScript, which return you absolute value .For example abs(11.80)=11.8 and abs(11.8)=11.8 .After doing this you can compare easily .




Yo can use the Abs() function of VBScript, which return you absolute value .For example abs(11.80) =11.8 and abs(11.8)=11.8 ,So now if you want to force the calculated number to keep 2 placed to the right of the decimal ,You can easily concatenate 0 with the returned values as
x=Abs(11.8)
y=x&"0"
Now if you will see y is assigned with 11.80 . Please tell if you need further clarification .