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

Get values with decimals inside IIF statement

Status
Not open for further replies.

Niki_S

Programmer
Jun 4, 2021
232
0
0
LK
Code:
SELECT _DelDtl
	IF  cStatus='Yes' THEN
		_DelPcs=_DelQty.DelQty/Lot_Desp.Tot_Desp*Colr_Desp.Tot_Desp
		REPLACE Delvr_Pcs WITH IIF((_DelPcs - int(_DelPcs)) = 0.5,round((_DelQty.DelQty/Lot_Desp.Tot_Desp*Colr_Desp.Tot_Desp),0)- 0.5,round(_DelQty.DelQty/Lot_Desp.Tot_Desp*Colr_Desp.Tot_Desp,0))
	ELSE
		IF Lot_CI.Tot_CI=0 
			SELECT _DelDtl
			REPLACE Delvr_Pcs WITH 0
		ELSE
			SELECT _DelDtl
			_DelPcs=_DelQty.DelQty/Lot_CI.Tot_CI*_DelDtl.nCiQty 
			REPLACE Delvr_Pcs WITH IIF((_DelPcs- int(_DelPcs)) = 0.5,round((_DelQty.DelQty/Lot_CI.Tot_CI*_DelDtl.nCiQty),0)- 0.5,round(_DelQty.DelQty/Lot_CI.Tot_CI*_DelDtl.nCiQty,0))
		ENDIF 
	ENDIF

This is my code and I did this for only 0.5 values.
as and example I can get ,
Code:
stylecode        lotname            lotcolor          del_pcs
26752            A1                 WHITE             1.5
26752            A1                 BLACK             1.5
26752            A1                 RED               1.5
26752            A1                 BLUE              1.5
according to the above table I need to get total as 6. It comes like this, 6/4*1 = 1.5.

Now I have another and I need to get it like , 207/4*1=51.75. But it comes as 52 and I want to get my output as 207.

How can I get values with decimals and replace them into my _DelDtl? I need to replace them with decimals using my IIF statement.


Thank you
 
You're using Round() with 0 decimals. Well, then you only get integers. Then you subtract 0.5, which get's you to values with .5, but never .75

You should rethink your rounding logic, it'll always subtract 0.5, that seems wrong.

Chriss
 
Okay then can I do something like this?
Code:
DvrlPcs
154.85
140.02
132.45

If I got my results like this can I round my results by looking only the first decimal number something like this.
Code:
DvrlPcs
155
140
132
And I want to get my final result as 427.
How can I do this?

Thank you
 
Okay, so the topic is rounding the total to the next integer (or is it to the next .5?)

One idea to think about: If you want to round to next .25, first multiply by 4, then round to integers and divide the result by 4 again.

I once had to program a similar 100% problem by rouding to some digits number and then assign the difference to 100% to the largest value. You could also go for such a strategy.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top