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 7956
> 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,s trDenom,intDeci mal)
Divide = 0
if IsNumeric(strNo m) and IsNumeric(strDe nom) then
if CDbl(strNom) > 0 and CDbl(strDenom) > 0 then
if IsNumeric(intDe cimal) then
intDecimal = FormatNumber(CD bl(Abs(intDecim al)),0)
else
intDecimal = 2
end if
Divide = FormatNumber(CD bl(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 reports at the plan (overall totals), department and division
levels which have sorting and grouping implemented with this new
|
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
display 17% and hold the value of seventeen percent.
I have the control propertes set to the following:
Name: comflatpercent
Format: percent
|
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 % 100); // Mod
frame = ((char)((tmp1/10)+48));
tmp1 = (tmp2 % 10);
|
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 = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2};
short int result = a / b; 'division
without additional lib's and header files, only in standart C.
|
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 problem
double percent_00_01 = 1D / 10000D
double percent_00_10 = 1D / 1000D
double percent_01_00 = 1D / 100D
double percent_10_00 = 10D / 100D
| |
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' division by zero and
just punch up a 0 result where such division is encountered so that I
can remove the where-clause?
Here's the query, I think it's very clear what I want to do:
select substr(tablespace_name, 1, 120) as TBSPC_NAME, used_pages,...
|
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 check
'Check if the quarter on quarter percentage change is significant
If Abs(Worksheets("PreviousData").Range("J3") - Worksheets("PreviousData").Range("K3")) / Abs(Worksheets("PreviousData").Range("K3")) * 100 >= 100 Then
...
|
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-
dependent,so,is my understanding of this true(positive division and
mod is guaranteed while negative is not)? thx for your help in
advance..
|
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 problems
later). Apparently Point is a struct, a value type, and it does not
behave like a classic structure (in my mind's eye, and see below).
Traditionally I think of a classic structure as simply an object where
every member is public. But with...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |