I have some values that I want to display as percent, such as the
retail price/wholesale price. In some instances, the wholesale price
is zero, so I get a division by zero error.

What can I do to avoid this?

Also, how can I get this to only show two decimals, instead of it
going .##### the way it does. I want it to look like .45%

Thanks a million,

Bill

Re: Formatting percent and dealing with division by zero problems by Aaron

Aaron
Thu Aug 28 20:26:45 CDT 2003

> I have some values that I want to display as percent, such as the
> retail price/wholesale price. In some instances, the wholesale price
> is zero, so I get a division by zero error.
>
> What can I do to avoid this?

if wholesaleprice > 0 then
response.write retailprice / wholesaleprice
else
response.write retailprice / retailprice
end if

> Also, how can I get this to only show two decimals, instead of it
> going .##### the way it does. I want it to look like .45%

Look at the formatnumber / formatpercent functions.



Re: Formatting percent and dealing with division by zero problems by dlbjr

dlbjr
Thu Aug 28 22:45:22 CDT 2003

function Divide(strNom,strDenom,intDecimal)
Divide = 0
if IsNumeric(strNom) and IsNumeric(strDenom) then
if CDbl(strNom) > 0 and CDbl(strDenom) > 0 then
if IsNumeric(intDecimal) then
intDecimal = FormatNumber(CDbl(Abs(intDecimal)),0)
else
intDecimal = 2
end if
Divide = FormatNumber(CDbl(strNom) / CDbl(strDenom),intDecimal)
end if
end if
end function

'Example
Response.Write Divide(234,321,3)




-dlbjr

invariable unerring alien