|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Divide By Zero - How to Prevent with the following statementLadies / Gentlemen
Would one of you take a stab a converting the following statement so that I do not have to worry about difide by zero errors. Z4.ProfitPercent = ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) * Z4.TotalPOSMovement ) / ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) - Z4.CurrentUnitCost ) * Z4.TotalPOSMovement ) ) Thank You Mark Moss Mark Moss wrote:
> Would one of you take a stab a converting the following statement so What do you want ProfitPercent to be set to if one of the denominators> that I do not have to worry about difide by zero errors. > > > Z4.ProfitPercent = ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) > * Z4.TotalPOSMovement ) / ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) - > Z4.CurrentUnitCost ) * Z4.TotalPOSMovement ) ) is zero? Chris
Zero -- would be fine. Mark Moiss Show quote "Chris Lim" <blackca***@hotmail.com> wrote in message news:1157182145.437325.70410@m79g2000cwm.googlegroups.com... > Mark Moss wrote: >> Would one of you take a stab a converting the following statement >> so >> that I do not have to worry about difide by zero errors. >> >> >> Z4.ProfitPercent = ( ( ( Z4.CurrentPrice / >> Z4.CurrentSplit ) >> * Z4.TotalPOSMovement ) / ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) - >> Z4.CurrentUnitCost ) * Z4.TotalPOSMovement ) ) > > What do you want ProfitPercent to be set to if one of the denominators > is zero? > Mark Moss wrote:
> Chris Taking markc's simplified formula:> > > Zero -- would be fine. Z4.ProfitPercent = COALESCE(Z4.CurrentPrice / NULLIF(Z4.CurrentPrice-(Z4.CurrentUnitCost*Z4.CurrentSplit), 0), 0) You appear to have Z4.TotalPOSMovement in both denominator and
numerator so it cancels out. Rearranging the calculation gives this Z4.ProfitPercent = Z4.CurrentPrice / NULLIF(Z4.CurrentPrice-(Z4.CurrentUnitCost*Z4.CurrentSplit),0) Gentlemen
I want to thank you for your very fast and useful help Mark Moss Show quote "Mark Moss" <markm***@adelphia.net> wrote in message news:eKJCS4lzGHA.1252@TK2MSFTNGP04.phx.gbl... > Ladies / Gentlemen > > > Would one of you take a stab a converting the following statement > so that I do not have to worry about difide by zero errors. > > > Z4.ProfitPercent = ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) > * Z4.TotalPOSMovement ) / ( ( ( Z4.CurrentPrice / Z4.CurrentSplit ) - > Z4.CurrentUnitCost ) * Z4.TotalPOSMovement ) ) > > > > Thank You > > > Mark Moss > |
|||||||||||||||||||||||