Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract decimal portion of the number

Status
Not open for further replies.

EKC

Technical User
Jan 13, 2001
43
0
0
CA
Hi,
I have 2 questions:
1.I need to extract decimal portion of the number,multiply it with 0.6 and add it again .Example:
6.45= 6 + (45*0.6)=6.27
2.What function is used to substract dates
Thanks,
Lyn
 

[red]
2.What function is used to substract dates
[/red]
dDateanswer = dDate2-dDate1

The answer is in days

[red]
1.I need to extract decimal portion of the number,multiply it with 0.6 and add it again .Example:
6.45= 6 + (45*0.6)=6.27
[/red]

VAL(SUBSTR(STR(nNum,4,2),1,1))+(45*0.6)
 
I think the decimal portion might be better extracted with:

function myFunc
parameters NumIn
private NumIn,myValue,IntBit,DecBit

IntBit = Int(NumIn) && 6
DecBit = (NumIn - IntBit) * 10 && 45

myValue = IntBit + (DecBit*.6) && 6.27

return(myValue)

Regards

Griff
Keep [Smile]ing
 
EKC,
Regarding your question to "What function do I use to subtract dates", MGAGNON supplied you with how to get the "Number of days" between two dates, but if you need to take a date, and decrese it by a number of days, it is just as easy. Any date can have an integer added or subtracted from it, simply by issuing:

NewDate = Date()-2 && Skip 2 days

In which case, you would get a DATE result in new date, that is two days ago. (The DATE() function gives you the "Current" date, (at least according to your computers system clock... so if it's date is wrong, you will get the wrong answer...)

You can just as easily skip ahead a whole week, or two with:

NewDate = Date() + 7 && Skip 1 week
or
NewDate = Date() + 14 && Skip 2 weeks

You get the idea. However, if you want to move a "Month" (Since not all "Months" are 28 days long... (in fact, only 1), you cant use Date() + 28 to get an "Exact" skip of a month. Instead use:

NewDate = GOMONTH(Date(),1)
Assuming today's date is 8 Apirl, 2002 (08/04/2002) new date will return:
08/05/2002

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top