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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make the following command

Status
Not open for further replies.

gavri

Technical User
Jul 13, 2000
2
IL
Let's say I have 2.5, I'm looking for the function that will return:<br>- 2 (trunc in Pascal).<br>- 0.5 (frac in Pascal).<br>- 3 (round in Pascal).<br><br>I have 10/2, I'm looking for the function that will return:<br>- 4 (div in Pascal).<br>- 2 (mod in Pascal).<br><br>Hope I made myself clear. Thanks.
 
um you can always add to your old thread by typing in this box down here when viewing the thread and clicking Submit.<br><br>well in the frac thing, if you just want after the decimal, I belive thats say<br><br>A = 2.5<br><br>A = A - Round(A,0)<br><br>I dont know if I have it correct, but if you were to round off the decimal so that there is no decimal place, subtracting that value would remain the decimal, round should work the same way for the 3 value up there, only its Round up instead of down. it appears, Trunc is Round down, frac is that function above, and round is round up.<br><br>far as the div/mod, I dont see how you get 2 from a modula, if you devided 10 by 2, you dont get anything remaining, but rather if you did a modula of 7/3 you would get 1 remaining. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Hey! does 10 divided by 2 equal to 4?????<br><br>I only have QB 4.5, so in order to return the <i>frac</i> or <b>most</b> of the Pascal functions you're mentioning, I'd have to first convert the number to string and add code to extrapulate the necessary information.<br><br>However, if I wanted to <i>round</i> off a number (if it's low enough), the fastes way would be to force the number from <i>Single Data Type</i> in to <i>Integer Data Type</i>. (example to follow)....<br><br><b>A = 7.5<br>A% = A<br>PRINT &quot;Normal (A): &quot;; A<br>print &quot;Forced (A): &quot;; A%<br><br><font color=red>Output:<br>Normal (A): 7.5<br>Forced (A): 8</font><br><br>A = 4.2<br>A% = A<br>PRINT &quot;Normal (A): &quot;; A<br>print &quot;Forced (A): &quot;; A%<br><br><font color=red>Output:<br>Normal (A): 4.2<br>Forced (A): 4</font></b><br><br><br>I think that kb244 is right on the money about subtracting the whole number and being left with only the fraction. (example to follow)...<br><br><b>A = 4.2<br>AA = VAL(MID$(STR$(A), INSTR(STR$(A), &quot;.&quot;), LEN(STR$(A)))<br>PRINT &quot;Normal (A): &quot;; A<br>PRINT &quot;Forced (A): &quot;; AA<br><br><font color=red>Output:<br>Normal (A): 4.2<br>Forced (A): .2</font></b><br><br><br>Hope this helps a little. :~) <p> <br><a href=mailto: > </a><br><a href= > </a><br>Why do gas stations have signs saying No Smoking, yet they sell cigaretes?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top