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

If statements on decimal portion of value 3

Status
Not open for further replies.

Lhuffst

Programmer
Jun 23, 2003
503
US
Does anyone know how to do an if statement on the decimal portion of a value?
@days
Local Numbervar nWorkDays;
nWorkDays := ({@WorkDays} - {@SumLeaveFinal})/8;
this value will change for each person for each month [/color blue]

for example:
I need to format out the following:
If nWorkDays = 18.00 then print 18.00
if nWorkDays are from 18.01 to 18.49 then print 18+
if nWorkDays = 18.50 then print 18.50
if nWorkDays are from 18.51 to 18.99 then print 19+

I know how to do it on the whole value but am not sure how to extract just the decimal portion.
Thanks
Lhuffst
 
Hi,
Maybe something like:

Code:
If 
(nWorkDays = Truncate(nWorkDays) OR (nWorkDays - Truncate(nWorkDays)) = .50 )
Then
ToText(nWorkDays,2)
  Else
   If nWorkDays - Truncate(nWorkDays) IN .01 to .49
    Then
    ToText(Truncate(nWorkDays)) + "+"
   Else
    If nWorkDays - Truncate(nWorkDays) IN .51 to .99
     Then
      ToText(Truncate(nWorkDays + 1)) + "+"

be sure that nWorkDays if formatted to always have 2 decimal places.



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Thanks, the formula works great but I am having a problem with the formatting of the result.

My real value is 18.38 so I want it to print 18+. What it is actually printing is 18.00+.

How would I get rid of the .00? Any ideas? The part that confuses me is why the field tacks on the .00. If it was a numerical number I could see it but I tried to make sure that it didn't contain any decimals (edit format option) and it sees it as a string.

Thanks much for all the help. As I said, your formula works like a champ, I just need to figue out how to make only the resultants print in this pattern:
18.00
18+
18.50
19

lhuffst
 
modify the last line to
ToText(Truncate(nWorkDays + 1),0) + "+
 
Sorry need to add the 0 decimal place flag to both conditions

If
(nWorkDays = Truncate(nWorkDays) OR (nWorkDays - Truncate(nWorkDays)) = .50 )
Then
ToText(nWorkDays,2)
Else
If nWorkDays - Truncate(nWorkDays) IN .01 to .49
Then
ToText(Truncate(nWorkDays),0) + "+"
Else
If nWorkDays - Truncate(nWorkDays) IN .51 to .99
Then
ToText(Truncate(nWorkDays + 1),0) + "+
 
Hi,Good catch dunlop1975,
I forgot that converting the truncated number ( which would have no decimals) to text would add back the decimal portion as .00 unless explicitly formatted not to.




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top