473,503 Members | 8,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting percent and dealing with division by zero problems

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
Jul 19 '05 #1
4 7925
> 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.
Jul 19 '05 #2
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
Jul 19 '05 #3
Thank you for the function! For your own knowlede, in order to calculate
the percent markdown from a retail price, the correct way to do it is
(denominator - numerator)/denominator

so if we're selling a $10 dollar item for $9, and we want to show that
is a 10% discount, it would be
(10-9)/10
1/10 = 10%

Your equation simply showed the numerator over the denominator.

By the way, this isn't adding the percent sign, I have to concatenate it
manually. Any way for that formatting to happen with a function?

Thanks again,

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4
> By the way, this isn't adding the percent sign, I have to concatenate it
manually. Any way for that formatting to happen with a function?


Have you looked at the formatpercent function?
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2712
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
3
6594
by: Nothing | last post by:
This is going to be a really stupid question, but I am having a problem with the percent format in a control on a form. My end goal is that I want the user to enter 17 and have the control...
8
29405
by: silentlights | last post by:
Hi, Is there a possibiliy to improve division or Modulo operations in the following, tmp1 = 123; tmp2 = 123; frame = ((char)((tmp1/100)+48)); // Division tmp1 = (tmp2...
9
12731
by: Marcin | last post by:
How I can make division of two numbers placed in arrays, example: short int a = {2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}; short int b =...
7
6340
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
2
31043
by: Pakna | last post by:
Why do I have a zero result on this query for all non-zero rows? Do I have to declare specifically the precision of ratio division? How do I do that? And is there a way to make DB2 'ignore'...
0
1276
by: LJ72 | last post by:
Hi I have taken over someone elses work and dont know VB at all. I am trying to work out percentage changes between two quarters data and am using the following formula. 'Box 4072 Vet...
7
6734
by: jackie | last post by:
I know in c that 3/2 gets 1 and 3%2 is also 1,and i think this is guaranteed by C99(is that true?),but on the other hand,-3/2 may be -1 or -2,and -3%2 may be -1 and 1 respectively,it is implement-...
0
2177
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.