Home All Groups Group Topic Archive Search About

Divide By Zero - How to Prevent with the following statement

Author
2 Sep 2006 7:04 AM
Mark Moss
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

Author
2 Sep 2006 7:29 AM
Chris Lim
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?
Author
2 Sep 2006 5:10 PM
Mark Moss
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?
>
Author
2 Sep 2006 10:44 PM
Chris Lim
Mark Moss wrote:
> Chris
>
>
>         Zero -- would be fine.

Taking markc's simplified formula:

Z4.ProfitPercent = COALESCE(Z4.CurrentPrice /
NULLIF(Z4.CurrentPrice-(Z4.CurrentUnitCost*Z4.CurrentSplit), 0), 0)
Author
2 Sep 2006 9:14 AM
markc600
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)
Author
3 Sep 2006 12:18 AM
Mark Moss
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
>

AddThis Social Bookmark Button