Micro Focus QTP (UFT) Forums
Dividing a term into years and months using mod operator in VBScript - 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: Dividing a term into years and months using mod operator in VBScript (/Thread-Dividing-a-term-into-years-and-months-using-mod-operator-in-VBScript)



Dividing a term into years and months using mod operator in VBScript - Brian.Osborne - 02-18-2011

I need to force a number to have decimal places so I can split it.

Here is the scenario.
I have a term in months ranging from 1 to 480. I need to split this into years and months.

This is what I have...
Code:
TermYears = Term/12
    myTermSplit = Split(TermYears, ".")
    myNewTermYears = myTermSplit(0) & myTermSplit(1)
    TermYears = mySplit(0)
    TermMonths = mySplit(1)*12

This issue is that when the number is divisible by 12 qtp takes off the decimal so the split fails.

Any way around this problem?
I've searched these boards and several others with nothing I've tried working. Looking for a creative solution.


RE: Forcing decimal place formating - Ankur - 02-18-2011

See if this will help -
Code:
Dim iTerm  ' Term in months

iTerm = 479 'say

msgbox int(iTerm/12) & " years " & iTerm mod 12 & " months"