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 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.
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
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!
> 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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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 =...
|
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...
| |
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'...
|
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...
|
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-...
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |
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...
| |